# Form Email Submissions (PHP + SMTP)

All **Elementor forms** on the site send submissions to **smile@apexdentalrcm.com** via your server SMTP settings.

## How it works

Each page includes:

```html
<script src="/forms/form-handler.js" defer></script>
```

When a visitor submits any `.elementor-form`:

1. JavaScript sends the data to `/forms/submit.php`
2. PHP sends an email via **PHPMailer** + SMTP
3. The visitor sees a success or error message on the form

## Email subject (identifies the form)

Each email subject line looks like:

```
[Apex Dental RCM] New Inquiry - Apex Dental RCM — Contact Us & Get Expert Dental Billing Support Now
```

| Part | Source |
|------|--------|
| Form name | `name` / `aria-label` on the form (e.g. **New Inquiry**, **New Subscriber**, **New Form**) |
| Page title | Browser page title + hidden `referer_title` field |

The email body includes the form name, page URL, page title, and all submitted fields with readable labels.

## Form types on the site

| Form name | Typical use |
|-----------|-------------|
| **New Inquiry - Apex Dental RCM** | Main contact / inquiry form |
| **New Subscriber** | Footer email subscribe |
| **New Form** | Popup / CTA forms (identified by page title in subject) |

---

## Setup on live server

### 1. Upload files

Upload these to your server:

- `forms/` folder (all files except keep `config.php` local)
- `vendor/` folder (PHPMailer from Composer)
- `composer.json` and `composer.lock` (optional, for updates)

Or run on the server:

```bash
composer install --no-dev
```

### 2. Configure SMTP

Copy the example config:

```bash
cp forms/config.example.php forms/config.php
```

Edit `forms/config.php` and set your **email account password**:

```php
'smtp' => [
    'host' => 'mail.apexdentalrcm.com',
    'port' => 465,
    'encryption' => 'ssl',
    'username' => 'smile@apexdentalrcm.com',
    'password' => 'YOUR_EMAIL_PASSWORD_HERE',
],

'to_email' => 'smile@apexdentalrcm.com',
```

### 3. Server email settings (reference)

| Setting | Value |
|---------|--------|
| **SMTP server** | `mail.apexdentalrcm.com` |
| **SMTP port** | `465` (SSL/TLS) |
| **Username** | `smile@apexdentalrcm.com` |
| **Password** | Your email account password |
| **Authentication** | Required |

`forms/config.php` is in `.gitignore` — do not commit passwords to git.

### 4. Test

1. Open any page with a form (e.g. Contact Us)
2. Submit the form
3. Check **smile@apexdentalrcm.com** inbox
4. Confirm the subject line identifies the form and page

---

## Local testing (Laragon)

1. Copy `forms/config.example.php` → `forms/config.php`
2. Enter the real SMTP password
3. Ensure PHP and `vendor/` (Composer) are present
4. Visit `http://mydentalrevenue.test/contact-us/` and submit a test form

**Note:** Forms do not work on `file://` URLs — use Laragon `http://`.

---

## Re-inject script on new HTML pages

If you add new static HTML pages:

```bash
node scripts/inject-form-handler.js
```

---

## Troubleshooting

| Problem | Fix |
|---------|-----|
| “Form mail is not configured” | Create `forms/config.php` from `config.example.php` |
| “PHPMailer is missing” | Run `composer install` or upload the `vendor/` folder |
| “SMTP password is not set” | Add password in `forms/config.php` |
| Email not received | Check spam folder; verify SMTP credentials with your host |
| Form does nothing | Open browser DevTools → Network; check `/forms/submit.php` response |
| Works locally, not on live | Ensure live server has PHP, SSL outbound on port 465, and `vendor/` uploaded |

---

## Files

```
forms/
  config.example.php   ← copy to config.php
  config.php           ← SMTP password (not in git)
  submit.php           ← receives POST, sends email
  form-handler.js      ← intercepts all Elementor forms
  .htaccess            ← blocks web access to config.php

vendor/                ← PHPMailer (Composer)
composer.json
scripts/inject-form-handler.js
```
