# AI Nerd Network — forms SMTP setup (operator)

**Hub (Next.js / Vercel):** https://www.ainerdnetwork.com  
**PHP API host (InMotion):** https://forms.ainerdnetwork.com  

| Form | Page | Endpoint | Notify mailbox |
| ---- | ---- | -------- | -------------- |
| Suggest a platform | `/companies` | `/send-platform-suggest.php` | **feedback@ainerdnetwork.com** |
| Connect | `/connect` | `/send-connect.php` | **info@ainerdnetwork.com** |

Same SMTP approach as **theonenamedwill.com** (InMotion, no Composer). **Port 465 + SSL.**

The public site cannot run PHP on Vercel. Forms POST cross-origin to this subdomain.

---

## Weird / easy-to-miss InMotion steps

1. **DNS for the subdomain** must point at **InMotion**, not Vercel.  
   - In Vercel DNS (ainerdnetwork.com zone): add **`forms`** as an **A** record to your InMotion shared IP, **or** a **CNAME** if InMotion gives you one for subdomains.  
   - In InMotion cPanel: create subdomain **`forms.ainerdnetwork.com`** and note its **document root** (e.g. `public_html/forms`).

2. **Create both mailboxes** before testing:  
   - `feedback@ainerdnetwork.com`  
   - `info@ainerdnetwork.com`  
   Each needs its **own password**. SMTP auth must use a **real** mailbox that exists.

3. **SMTP host is not always `mail.domain.com`.**  
   Open cPanel → Email Accounts → **Connect Devices** for that mailbox → **Outgoing Server (SMTP)**. Copy that host **exactly** into `config.php`.

4. **`from_email` / SMTP username must match** the mailbox you authenticated as. Do not send `From: info@…` while logged in as `feedback@…` (InMotion will reject it).

5. **`config.php` is created on the server only** — copy from `config.example.php`. Never commit filled passwords to GitHub.

6. **First live 500 “configuration missing”** usually means the file is named wrong or in the wrong folder. Exact path: **`forms-api/lib/config.php`** on the server (same tree as this package).

7. Set **`expose_errors` => true** once to see the real SMTP error on the form, then set it back to **`false`**.

---

## 1. Provision email (cPanel)

For **ainerdnetwork.com** in InMotion:

1. Email Accounts → Create **feedback@ainerdnetwork.com**  
2. Create **info@ainerdnetwork.com**  
3. Save both passwords somewhere safe (password manager)

Optional: webmail login smoke-test each inbox.

---

## 2. Create subdomain + FTP the API

1. cPanel → **Subdomains** → **forms.ainerdnetwork.com**  
2. FTP **contents** of this `forms-api/` folder into that subdomain’s docroot:
   - `send-platform-suggest.php`
   - `send-connect.php`
   - `lib/` (Mailer.php, bootstrap.php, config.example.php)
   - `data/` (empty rate-limit folder is fine; PHP creates files)
3. On the server: copy **`lib/config.example.php` → `lib/config.php`**  
4. Edit `config.php`: real passwords + SMTP host from Connect Devices for each account.

Quick check: visit `https://forms.ainerdnetwork.com/send-connect.php` in a browser — should return JSON **Method not allowed** (405). That means PHP is running.

---

## 3. DNS (Vercel zone → InMotion)

Because the domain’s nameservers are on **Vercel**:

1. Vercel → Project / Domains → DNS for **ainerdnetwork.com**  
2. Add record for **`forms`**:
   - Prefer **A** → InMotion server IP (cPanel → Server Information / Shared IP)  
   - Or CNAME if InMotion documents one for this account  
3. Wait for DNS (often a few minutes; sometimes longer)  
4. In InMotion, ensure the subdomain is active and SSL is issued (AutoSSL / Let’s Encrypt for `forms.ainerdnetwork.com`)

---

## 4. Hub env (Vercel)

In the **ainerdnetwork** Vercel project:

```
NEXT_PUBLIC_ANN_FORMS_API_BASE=https://forms.ainerdnetwork.com
```

Redeploy the hub after setting it. Without this env var, the Next app defaults to that same URL in production code.

---

## 5. Live test

1. Open https://www.ainerdnetwork.com/companies → Suggest a platform (include your email) → confirm **feedback@** receives mail.  
2. Open https://www.ainerdnetwork.com/connect → send a message → confirm **info@** receives mail.  
3. Check spam folders once.

Local Next (`localhost:3002`) is allowed in `allowed_origins`, but PHP must still be reachable on the live forms host (local Next cannot run this PHP).

---

## Troubleshooting

| Symptom | Fix |
| ------- | --- |
| CORS / blocked by browser | Confirm `allowed_origins` includes `https://www.ainerdnetwork.com` |
| Config missing | Create `lib/config.php` from example on the **forms** host |
| SMTP auth failed | Wrong password or username; use full email as username |
| Wrong host | Copy Outgoing Server from Connect Devices |
| Port issues | Use **465 + ssl** (not 587 + tls) unless Connect Devices says otherwise |
| Origin not allowed | Add the exact Origin string (scheme + host, no path) |
