# Apex WPForms Email Troubleshooting

WPForms on apextrackexperience.com (wphost02, RunCloud CPX21) uses WP Mail SMTP plugin to send through c1113726.sgvps.net:2525.

## Known Failure Modes

### 1. PHP Serialization Corruption

The password stored in WP Mail SMTP settings uses PHP serialized format. If the password contains special characters, the serialized length (s:N:) can become wrong:

```
s:72:"apex.track!!"   ← WRONG: password is 13 chars, not 72
s:13:"apex.track!!"  ← CORRECT
```

**Symptom:** SMTP auth fails silently. WP Mail SMTP can't read the password. Registration emails never send. The site shows "form submitted" but no email arrives.

**Fix:** UPDATE wp_options SET option_value = REPLACE(option_value, 's:WRONG_LEN:"', 's:CORRECT_LEN:"') WHERE option_name = 'wp_mail_smtp'

### 2. Sender Address Contains Multiple Emails

The sender_address field in form notifications must be a single email address. WPForms allows entering comma-separated emails but this creates an invalid From header:

```
"sender_address":"contact@apextrackexperience.com, g@germainebrown.com"  ← INVALID
"sender_address":"contact@apextrackexperience.com"                       ← VALID
```

**Symptom:** SMTP server rejects with "Message rejected. domain.com is not currently owned by sender"

**Fix:** UPDATE wp_posts SET post_content = REPLACE(post_content, 'sender_address":"...", g@...', 'sender_address":"contact@apextrackexperience.com') WHERE ID IN (form_ids)

### 3. Password Format Changed by WP Mail SMTP Plugin Update

Plugin updates can re-serialize the password with incorrect length. Check after every WP Mail SMTP or WPForms update.

## Manual Verification

```bash
ssh -i /root/.ssh/itpp-infra root@5.161.62.38 '
mysql -u apextrackexperience_1781549652 -p"K3E1ZZWvHDu0q8ZmoBCAhzKUZawEapdGBlbaPME1sOTKgGk9FCuYS" apextrackexperience_1781549652 -e "
SELECT option_value FROM wp_options WHERE option_name = \"wp_mail_smtp\";
" | grep -o "s:[0-9]*:\\\\\"apex" | head -1
'
```

If the length (s:N) is wrong, apply fix #1.

## Watchdog Cron

The cron `apex-mail-watchdog` runs every 5 min on Core:
- Sends test SMTP email via the Apex SMTP server
- Checks wp_wpmailsmtp_debug_events for recent failures
- Silent on success, alerts on failure

Script: /root/.hermes/scripts/apex-mail-watchdog.sh
Log: /var/log/apex-mail-watchdog.log
