If you look after a WordPress site for a business, you can learn within about an hour that its contact form has stopped delivering leads. The form can keep showing its thank-you message while the entry is never stored, the notification is never sent, or the email lands in spam. Often nobody notices until a client asks why enquiries dried up, weeks after the break. The answer is to watch the form the way you watch uptime. Store every entry, compare entries with sent mail each morning, and send an hourly test submission that must reach a real inbox. With those three checks in place, a broken form raises an alert the same hour instead of showing up in next month’s sales numbers.
What you’ll accomplish
- Know the six places a submission can vanish while the visitor sees success, and which check catches each one.
- Confirm once that nothing on the site intercepts outgoing mail.
- Keep a stored copy of every submission and a log of every email WordPress tries to send.
- Run a daily count that flags any day where entries and notification emails disagree.
- Run an hourly test submission from outside the server, and get an alert when its email has not arrived 10 minutes later.
Prerequisites
- WordPress 5.7 or later, the release that added the
pre_wp_mailfilter discussed below. - Shell access and WP-CLI on the web server. WP-CLI lets you query WordPress from the terminal;
wp --infoprints its version if it is installed. - Contact Form 7 as the worked example. The REST details below were checked against the 6.x source; the monitoring idea works for any form plugin, and the plugin-specific parts are flagged.
- A second machine for the hourly test, such as a small VPS or your monitoring host. Running it on the web server itself means a dead server also kills the check that should report it.
curlbuilt with IMAP support (most Linux packages are), and IMAP access to the mailbox that receives the notifications, with a password or app password. Microsoft 365 mailboxes no longer accept password logins over IMAP; see Troubleshooting.- An account on a heartbeat monitor, a service that alerts when an expected ping stops arriving. Healthchecks.io and the push monitor in Uptime Kuma both work.
- Example values: site
https://example.com, form ID42, notifications sent tosales@example.com, cPanel usercpuser.
How it works
A submission crosses eight stages before a person reads it. The browser runs the form’s JavaScript. A page cache may serve an old copy of the page. The data is posted to an endpoint, either the WordPress REST API or admin-ajax.php. The form plugin validates it, stores an entry if storage is on, and calls wp_mail(), the WordPress function that sends email. An SMTP relay accepts the message, and the receiving mail server decides whether it lands in the inbox.
The visitor’s success message only proves that the endpoint answered. Everything after that can fail without the visitor, or you, seeing anything.
| Where it breaks | What the visitor sees | What is lost | Which check catches it |
|---|---|---|---|
| Minified or delayed JavaScript breaks the submit handler | Nothing, or a theme’s own “thanks” | The whole submission | Page check, entry count drops |
| Cached page carries an expired nonce (a one-time security token) | An error, or a success message the theme fakes | The whole submission | Entry count drops, 403 in the Network tab |
| Plugin replies success without storing anything | Success | The record | The stored-entry baseline |
| Entry saved, but the relay refuses the notification | Success with most plugins | The email | Daily count, mail log error column |
A pre_wp_mail callback returns early | Success | The email, while logs look normal | Inbox check, the step 1 audit |
| Relay accepts the mail, receiver files it as spam or rejects it | Success | The email | Inbox check only |
The red mark in the diagram is the last row. It is the one stage where every log on your server says the message went out. A form that sends mail “From” the visitor’s own address fails DMARC (the receiver’s check that a sender’s domain authorised the mail) whenever that visitor’s provider publishes a strict policy, as Yahoo does. Nothing inside WordPress can see it.
Two rows need a closer look. WordPress nonces stay valid for 12 to 24 hours. A page cached longer than that hands visitors a dead token, and admin-ajax.php answers with HTTP 403 and the body -1. A REST call carrying the stale token gets 403 with “Cookie check failed”. Current Contact Form 7 releases do not send that token for logged-out visitors, so it is less exposed than many theme and builder forms.
The pre_wp_mail row is the sneakiest. WordPress runs the wp_mail filter first, then pre_wp_mail. Any callback on pre_wp_mail that returns a value ends the send right there, and wp_mail() returns that value. Mail loggers such as WP Mail Logging hook the earlier filter, so they record a normal-looking row with no error. The form plugin sees true and reports success. Staging sites and “disable email” helpers use this filter on purpose, and it sometimes survives a copy to production.
Step-by-step
1. Audit the mail path once for interceptors. Run these from the WordPress root:
wp eval 'var_dump( has_filter( "pre_wp_mail" ) );'
Example output:
bool(false)
bool(false) means nothing is hooked. If you see bool(true), list who registered it:
wp eval 'global $wp_filter; foreach ( $wp_filter["pre_wp_mail"]->callbacks ?? array() as $p => $cbs ) { foreach ( array_keys( $cbs ) as $id ) { echo $p, " ", $id, PHP_EOL; } }'
grep -rln "pre_wp_mail" wp-content/mu-plugins wp-content/plugins wp-content/themes
Example output:
10 staging_block_outgoing_mail
wp-content/mu-plugins/staging-mail.php
Then check that wp_mail() itself is the WordPress original, and list must-use plugins, which load on every request and never appear on the normal Plugins screen:
wp eval '$f = new ReflectionFunction( "wp_mail" ); echo $f->getFileName(), PHP_EOL;'
wp plugin list --status=must-use
The first command should print a path ending in wp-includes/pluggable.php. Any other file means a plugin replaced wp_mail(). Some SMTP plugins do that deliberately, so confirm it is one you installed on purpose. Read every must-use plugin you did not write.
2. Store every entry and log every email. Contact Form 7 keeps nothing by default. Flamingo, written by the same author, stores each submission as an inbound message. WP Mail Logging records every call to wp_mail() in its own table, including the error text when sending fails.
wp plugin install flamingo wp-mail-logging --activate
Each plugin prints Plugin installed successfully. and Plugin '…' activated., then WP-CLI ends with Success: Installed 2 of 2 plugins. Submit the form once from a browser, then check both stores:
wp post list --post_type=flamingo_inbound --post_status=publish --format=count
wp db query "SELECT mail_id, timestamp, receiver, error FROM $(wp db prefix)wpml_mails ORDER BY mail_id DESC LIMIT 1"
Example output:
1
+---------+---------------------+-------------------+-------+
| mail_id | timestamp | receiver | error |
+---------+---------------------+-------------------+-------+
| 3 | 2026-10-13 09:41:27 | sales@example.com | |
+---------+---------------------+-------------------+-------+
The count should be at least 1, and the last mail row should name sales@example.com with an empty error column. With other plugins, turn on their own entry storage instead of Flamingo. Gravity Forms, Fluent Forms and WPForms Pro store entries. WPForms Lite does not keep them in your database; its optional Lite Connect backup stores them on WPForms’ servers instead. For a deeper look at log retention and queries, see WordPress mail logging, what to log.
3. Reconcile entries against sent mail every morning. Save this as /home/cpuser/bin/form-reconcile.sh on the web server:
#!/bin/bash
# Compares yesterday's stored entries with notification emails to sales@example.com
cd /home/cpuser/public_html || exit 1
D=$(date -d yesterday +%F)
P=$(wp db prefix)
ENTRIES=$(wp post list --post_type=flamingo_inbound --post_status=publish \
--year="${D:0:4}" --monthnum="${D:5:2}" --day="${D:8:2}" --format=count)
MAILS=$(wp db query "SELECT COUNT(*) FROM ${P}wpml_mails WHERE DATE(timestamp) = '$D' AND receiver LIKE '%sales@example.com%'" --skip-column-names)
FAILED=$(wp db query "SELECT COUNT(*) FROM ${P}wpml_mails WHERE DATE(timestamp) = '$D' AND receiver LIKE '%sales@example.com%' AND error <> ''" --skip-column-names)
HOOKED=$(wp eval 'echo has_filter( "pre_wp_mail" ) ? "yes" : "no";')
echo "$D entries=$ENTRIES mails=$MAILS failed=$FAILED pre_wp_mail=$HOOKED"
if [ "$ENTRIES" -eq "$MAILS" ] && [ "$FAILED" -eq 0 ] && [ "$HOOKED" = "no" ]; then
curl -fsS -m 10 --retry 3 "$RECONCILE_HEARTBEAT_URL" > /dev/null
fi
Schedule it with crontab -e, replacing the URL with your own heartbeat check:
15 6 * * * RECONCILE_HEARTBEAT_URL='https://hc-ping.com/your-check-id' /bin/bash /home/cpuser/bin/form-reconcile.sh >> /home/cpuser/form-reconcile.log 2>&1
Example output in the log:
2026-10-12 entries=31 mails=31 failed=0 pre_wp_mail=no
The rule is one notification per stored entry when the form sends one email to sales@example.com. Both counts include the 24 daily test submissions from step 5, which is fine because each one also sends a notification. If the form also copies a second internal address, expect twice as many rows, and change the comparison to match. The heartbeat pings only when everything agrees, so a mismatch shows up as a missed ping. Reading the result:
entriesat or near 24 on a normal business day, once the probe runs: only the probe got through, so real submissions are dying before the plugin. Look at cache and JavaScript first.mailslower thanentries: some notifications were never attempted, often a conditional notification rule.mailshigher thanentries: something else also emailssales@example.com, such as a second form or WooCommerce order alerts. Add asubject LIKEcondition to both mail queries so they count only this form’s notifications.failedabove 0: the relay refused mail. Theerrorcolumn holds the reason.pre_wp_mail=yes: go back to step 1.
4. Build the hourly test submission. Contact Form 7 accepts submissions at /wp-json/contact-form-7/v1/contact-forms/<id>/feedback. The request must be multipart/form-data (otherwise HTTP 415) and must include _wpcf7_unit_tag (otherwise HTTP 400). The unit tag is the ID of the form’s wrapper on the page, such as wpcf7-f42-p7-o1. Any value made of letters, digits, dashes and underscores is accepted. Find the form ID first:
wp post list --post_type=wpcf7_contact_form --fields=ID,post_title
Example output:
+----+-----------------+
| ID | post_title |
+----+-----------------+
| 42 | Contact form 1 |
| 57 | Quote request |
+----+-----------------+
The field names are the second word inside each tag in the form editor, such as your-email in [email* your-email]. Then send one submission by hand from your monitoring host. Use the field names from your own form; these are the plugin’s defaults:
curl -s -X POST 'https://example.com/wp-json/contact-form-7/v1/contact-forms/42/feedback' \
-F '_wpcf7=42' -F '_wpcf7_unit_tag=wpcf7-f42-p7-o1' \
-F 'your-name=Form Probe' -F 'your-email=formprobe@example.com' \
-F 'your-subject=formprobe-manual-test' -F 'your-message=Automated form check, safe to delete.'
Example output:
{"contact_form_id":42,"status":"mail_sent","message":"Thank you for your message. It has been sent.","posted_data_hash":"8f2c1d0b6a4e93d7c5b1a0e2f4d6c8b9","into":"#wpcf7-f42-p7-o1","invalid_fields":[]}
mail_sent is the goal. validation_failed means a field name or required field is wrong. spam usually means reCAPTCHA, Turnstile or Akismet blocked the test. Contact Form 7 checks a wpcf7_skip_spam_check filter before any of those run, so let the probe through only when it presents a secret. Put this in wp-content/mu-plugins/form-probe.php, and define FORM_PROBE_KEY in wp-config.php as a long random string:
<?php
add_filter( 'wpcf7_skip_spam_check', function ( $skip ) {
$expected = defined( 'FORM_PROBE_KEY' ) ? FORM_PROBE_KEY : '';
$sent = isset( $_SERVER['HTTP_X_FORM_PROBE'] ) ? $_SERVER['HTTP_X_FORM_PROBE'] : '';
return ( '' !== $expected && hash_equals( $expected, $sent ) ) ? true : $skip;
} );
Repeat the curl with -H "X-Form-Probe: <your key>" and confirm mail_sent. Other plugins need their own route. Gravity Forms accepts POST /wp-json/gf/v2/forms/<id>/submissions, which runs its notifications like a normal submission. Forms that post to admin-ajax.php need their real field set, so read the request in the browser’s Network tab and copy it.
5. Check the inbox and alert on silence. Save /root/bin/form-probe.sh on the monitoring host. It submits, waits 10 minutes, then searches the mailbox that receives notifications for the unique subject:
#!/bin/bash
# Hourly form probe: submit, wait, search the inbox, ping the heartbeat on success
set -u
TOKEN="formprobe-$(date -u +%Y%m%d%H%M)"
RESP=$(curl -s -m 30 -X POST 'https://example.com/wp-json/contact-form-7/v1/contact-forms/42/feedback' \
-H "X-Form-Probe: $FORM_PROBE_KEY" \
-F '_wpcf7=42' -F '_wpcf7_unit_tag=wpcf7-f42-p7-o1' \
-F 'your-name=Form Probe' -F 'your-email=formprobe@example.com' \
-F "your-subject=$TOKEN" -F 'your-message=Automated form check, safe to delete.')
case "$RESP" in
*'"status":"mail_sent"'*) ;;
*) echo "$TOKEN submit failed: $RESP"; curl -fsS -m 10 "$PROBE_HEARTBEAT_URL/fail" > /dev/null; exit 1 ;;
esac
sleep 600
FOUND=$(curl -s -m 30 --user "$IMAP_USER:$IMAP_PASS" \
--url 'imaps://imap.example.com/INBOX' -X "SEARCH SUBJECT \"$TOKEN\"")
case "$FOUND" in
*'SEARCH '[0-9]*) curl -fsS -m 10 --retry 3 "$PROBE_HEARTBEAT_URL" > /dev/null; echo "$TOKEN ok" ;;
*) echo "$TOKEN no mail after 10 minutes"; curl -fsS -m 10 "$PROBE_HEARTBEAT_URL/fail" > /dev/null; exit 1 ;;
esac
Keep the secrets in /root/.form-probe.env (mode 600) as export lines for FORM_PROBE_KEY, IMAP_USER, IMAP_PASS and PROBE_HEARTBEAT_URL, then schedule it:
7 * * * * . /root/.form-probe.env && /bin/bash /root/bin/form-probe.sh >> /var/log/form-probe.log 2>&1
Example output in /var/log/form-probe.log:
formprobe-202610131307 ok
formprobe-202610131407 ok
formprobe-202610131507 no mail after 10 minutes
The IMAP search returns a line such as * SEARCH 4182 when it finds the message, and a bare * SEARCH when it does not. Set the heartbeat’s period to 1 hour with a 20-minute grace. On Healthchecks.io the /fail URL in the failure branches raises the alert at once. Uptime Kuma’s push monitor has no /fail path, so there the alert comes when the grace period runs out. A message that lands in the spam folder is not in INBOX, so the search finds nothing and the heartbeat goes quiet. That is the red failure, caught. The default Contact Form 7 subject includes [your-subject], which is why the token travels with the email. The recipients will see 24 test messages a day. Ask them for a mail rule that marks formprobe- subjects as read without moving them out of the inbox, and keep those messages out of the CRM.
6. Add a page check for cache and JavaScript failures. The probe enters at the endpoint, so it skips the browser and the page cache. Cover them with an uptime monitor keyword check on the contact page for wpcf7-form, and check how old the cached copy is:
curl -sI https://example.com/contact/ | grep -iE '^(age|cache-control|x-cache|cf-cache-status)'
Example output:
cache-control: public, max-age=3600
age: 1874
cf-cache-status: HIT
An age above 43200 seconds (12 hours) on a page whose form relies on a nonce means visitors can receive a dead token. Exclude that page from the cache or shorten its lifetime. A keyword check proves the form renders, not that its JavaScript works. For that, submit once from a real browser after every plugin or optimisation change, and watch step 3 for a drop to the probe’s 24 entries.
Validate it works
Break things on purpose, on a staging copy:
- Mail interceptor. Create
wp-content/mu-plugins/break-mail.phpcontaining<?php add_filter( 'pre_wp_mail', '__return_true' );. Run the probe script by hand against the staging URL. The submission still returnsmail_sentand WP Mail Logging shows a clean row, yet 10 minutes later the script printsno mail after 10 minutes. The reconciliation script, run by hand, reportspre_wp_mail=yesand skips its ping. Delete the file. - Dead relay. Point your SMTP plugin at a wrong password and submit once. The mail log
errorcolumn fills in, and the next morning’s reconciliation line showsfailed=1. - Heartbeat. Stop the cron entry for two hours and confirm the heartbeat service alerts you.
When all three alert and the healthy runs ping, monitoring is live.
Troubleshooting
- The probe gets HTTP 404 with
rest_no_route. A security plugin has disabled the REST API for visitors, which also breaks the real form. Allow thecontact-form-7/v1namespace. The spinner-side debugging lives in Contact Form 7 keeps spinning. - The probe gets 403 from the server, not from WordPress. A WAF (web application firewall) rule matched the request body. Find the rule ID in the WAF log and exclude it for that route only.
- The probe gets
spameven with the key. Check that the mu-plugin file is in place and thatFORM_PROBE_KEYinwp-config.phpmatches the value in/root/.form-probe.envexactly. A key with spaces or quotes is easy to mistype, so use letters and digits only. - The mail log shows the row, but the inbox never gets it. WordPress did its part. Work through relay logs, SPF, DKIM and DMARC as described in WordPress form emails not arriving.
- IMAP login fails. Google Workspace and Gmail accept an app password once 2-Step Verification is on. Microsoft 365 retired password logins for IMAP and requires OAuth 2.0, which this script does not handle. There, add a second recipient at a provider that allows IMAP passwords and search that mailbox, keeping in mind its spam filter is not the one your client uses.
When this is the wrong approach
On a site that gets two enquiries a month, the daily count adds little beyond what the probe already shows. Rely on the hourly probe there and skip step 3. Forms embedded from a CRM, such as a HubSpot or Salesforce form, never touch WordPress, so monitor them at the vendor. If notifications should go to several people or into a ticketing system, the design question belongs to building reliable form notifications. The WordPress reference for the pre_wp_mail filter and the Flamingo plugin page document the two pieces this setup depends on.
If alerts fire into an empty room after hours, that’s exactly what 24/7 Monitoring & Response closes — book a monitoring and response review.