Skip to content

Contact Form 7 spinning or not sending email: fixes

Fix Contact Form 7 when the submit button spins forever or the form says sent but no email arrives. Find the failing request, then the mail step behind it.

Contact Form 7 problems come in two shapes, and this article covers both. In the first, the submit button spins forever, with no green confirmation and no red error. In the second, the form finishes but the email never arrives. The spinner runs from the moment you submit until the browser receives a response it can read as JSON. Contact Form 7 5.x posts to the WordPress REST API at /wp-json/contact-form-7/v1/contact-forms/<id>/feedback, and the spinner stops when that request returns a body with a status field. A spinner that never stops means the request never returned, returned an error code, or returned something that was not JSON at all. Those are three different problems with three different fixes. A missing email is a separate case: the form reports mail_sent or mail_failed, and the fault is in WordPress mail or the server’s mail delivery, not in the form. The steps below separate these cases in order before you touch a single setting.

What you’ll accomplish

  • A definite answer to which hop of the submission chain fails: the network, the REST route, PHP, or the mail transport.
  • A reproducible curl call against the feedback endpoint, so you can test without a browser.
  • A working read of the status value Contact Form 7 returns, and what each value actually means.
  • A logged reason for mail_failed, captured from WPCF7_Submission rather than guessed at.
  • A clear line between problems you fix in WordPress and problems that live in the WAF, the cache, or the MTA.

Prerequisites

This guide assumes Contact Form 7 5.x on WordPress 6.x with PHP 8.x. Version matters: the REST submission path described here landed in Contact Form 7 5.0, and older guides that tell you to watch admin-ajax.php are describing 4.x behaviour that no longer exists. Check what you are running before you follow anything.

You need browser devtools with the Network tab, and shell access to the site — WP-CLI if the host provides it, plain SSH otherwise. Hosting differs here in ways that matter. On cPanel you usually have both WP-CLI and a per-account logs/error_log. On a managed WordPress platform you may have neither, and the PHP log lives behind a control panel viewer; in that case use the browser and curl steps and skip the wp eval ones. If you have no shell at all, you can still complete the diagnosis from devtools alone, but you will not be able to read why wp_mail() failed.

Throughout, example.com stands for the site and 42 for the form ID. Get the real ID with wp post list --post_type=wpcf7_contact_form --fields=ID,post_title, or read it out of the _wpcf7 hidden input in the page source.

How it works

Contact Form 7’s JavaScript intercepts the form submit, starts the spinner, and issues a fetch() to a REST route the plugin registers on rest_api_init under the contact-form-7/v1 namespace. The route for a submission is contact-forms/(?P<id>\d+)/feedback, and it accepts a multipart POST carrying the visitor’s fields plus Contact Form 7’s own bookkeeping fields: _wpcf7 (the form ID), _wpcf7_version, _wpcf7_locale, _wpcf7_unit_tag, and _wpcf7_posted_data_hash. A wp_rest nonce is sent in the X-WP-Nonce header, printed into the page when it was rendered.

Five stages of a Contact Form 7 submission from browser POST through REST dispatch, validation, mail send and JSON response, each paired with its failure mode

On the server the route runs validation filters, then spam checks, then — unless something aborted first — the mail step. The mail step fires wpcf7_before_send_mail, consults the wpcf7_skip_mail filter, and calls wp_mail(). Whatever happens, the route ends by returning a JSON object whose status is one of mail_sent, mail_failed, validation_failed, acceptance_missing, spam, or aborted, alongside a human-readable message. The JavaScript reads status, stops the spinner, and paints the response text.

That last sentence is the whole diagnosis. The spinner is not a state machine with a timeout — it stops on a parsed response and on nothing else. So a submission that hangs is never a Contact Form 7 configuration problem. It is a transport problem, a routing problem, or a PHP problem that destroyed the JSON before it reached the browser. Contact Form 7’s own documentation covers the form-building side; the mechanism above is WordPress REST API behaviour, and that is where the failures live.

Decision tree from a hanging spinner through four checks: request present, status code returned, status 200, and body parses as JSON

Step-by-step

  1. Read the failing request in devtools before changing anything. Open the page, open devtools, select the Network tab, filter on feedback, and submit the form. You are looking for one row.

    Name        feedback
    Status      200
    Type        fetch
    Size        1.2 kB
    Time        480 ms

    A row with Status still showing (pending) after ten seconds means the request left and never came back — go to step 5. A 404 or 403 means the route is blocked — step 4. A 200 that still leaves the spinner running means the body is not JSON — open the Response tab (not Preview, which hides raw text) and look at the first characters. HTML, a PHP warning, or a stray blank line before { all break the parse. No row at all means the JavaScript never ran; check the Console tab for an error and confirm a minifier has not mangled the plugin’s script.

  2. Reproduce the submission from the shell with curl. This takes the browser, the theme, and the cache out of the picture entirely.

    curl -s -o /tmp/cf7.json -w '%{http_code} %{content_type}\n' \
      -X POST 'https://example.com/wp-json/contact-form-7/v1/contact-forms/42/feedback' \
      -F '_wpcf7=42' \
      -F '_wpcf7_unit_tag=wpcf7-f42-p1-o1' \
      -F 'your-name=Endpoint check' \
      -F 'your-email=test@example.com' \
      -F 'your-subject=Endpoint check' \
      -F 'your-message=Endpoint check'

    The expected output is a single line: 200 application/json. Then read the body:

    cat /tmp/cf7.json

    A healthy response looks like {"contact_form_id":42,"status":"mail_sent","message":"Thank you for your message. It has been sent."}. Adjust the field names to match your form — your-name style names are Contact Form 7 defaults, not a requirement. If curl returns clean JSON while the browser hangs, the fault is in front of PHP: a WAF rule, a cache, or the page’s own JavaScript.

  3. Confirm the REST base is reachable at all. A blocked namespace produces a 404 that looks identical to a wrong form ID.

    curl -s -o /dev/null -w '%{http_code}\n' https://example.com/wp-json/contact-form-7/v1/

    200 means the namespace is registered and served. Then look at what it exposes:

    curl -s https://example.com/wp-json/contact-form-7/v1/ | head -c 200

    You should see {"namespace":"contact-form-7\/v1","routes":{ followed by the route table. A 404 here with a working /wp-json/ root means Contact Form 7 is not loading its REST registration — usually because the plugin is deactivated on the front end by an optimisation plugin. A 401 on both means something has hooked rest_authentication_errors to require login for every REST request; debugging WordPress REST API errors covers finding that filter.

  4. Read the PHP error log for the window in which you submitted. This is where a fatal inside a hook shows up, and it is the single most productive step when the response is a 200 with a broken body.

    wp config get WP_DEBUG_LOG
    tail -50 wp-content/debug.log

    If WP_DEBUG_LOG is unset, the entries are in the host’s log instead — tail -50 /home/cpuser/logs/error_log on cPanel. What you are hunting for is a line timestamped to your submission, such as PHP Fatal error: Uncaught Error: Call to a member function get_posted_data() on null in .../functions.php:214. A fatal at that point means PHP emitted HTML and then died, so the JSON never formed.

  5. Check whether wp_mail() works independently of Contact Form 7. If step 2 returned "status":"mail_failed", this splits a plugin problem from a transport problem.

    wp eval 'var_dump( wp_mail( "you@example.com", "CF7 transport check", "sent at " . gmdate( "c" ) ) );'

    bool(true) means WordPress handed the message off successfully and the fault is downstream. bool(false) means the handoff itself failed, and the reason is available from the wp_mail_failed action:

    wp eval 'add_action( "wp_mail_failed", function ( $e ) { echo $e->get_error_message(), PHP_EOL; } ); wp_mail( "you@example.com", "CF7 transport check", "body" );'

    Expect something specific, like SMTP connect() failed. or Could not instantiate mail function. The second message means PHP’s mail() is unavailable on this host, which is common on containerised platforms and is a hosting fact rather than a bug.

  6. Capture the real reason from WPCF7_Submission instead of guessing. Contact Form 7 knows why it failed; it just does not write it anywhere by default. Add a small must-use plugin.

    cat > wp-content/mu-plugins/cf7-debug.php <<'PHP'
    <?php
    add_action( 'wpcf7_mail_failed', function ( $contact_form ) {
        $submission = WPCF7_Submission::get_instance();
        error_log( sprintf(
            'CF7 mail_failed form=%d status=%s response=%s',
            $contact_form->id(),
            $submission ? $submission->get_status() : 'no-submission',
            $submission ? $submission->get_response() : 'no-response'
        ) );
    } );
    PHP

    Submit the form again and check the log. A line like CF7 mail_failed form=42 status=mail_failed response=There was an error trying to send your message. confirms the failure is in the mail step and not in validation. While you are here, rule out a hook that skips mail entirely:

    wp eval 'var_dump( has_filter( "wpcf7_skip_mail" ), has_action( "wpcf7_before_send_mail" ) );'

    A non-false result for wpcf7_skip_mail means some plugin is deliberately suppressing the send — a CRM integration or a payment add-on, usually. That is a configuration decision, not a fault, and it explains a form that reports success while no message is ever sent.

  7. Remove the mu-plugin when you are done. rm wp-content/mu-plugins/cf7-debug.php, and confirm with ls wp-content/mu-plugins/. Diagnostic code left in place becomes tomorrow’s mystery.

Contact Form 7 not sending email

Two different faults hide behind “Contact Form 7 not sending email”, and the form’s own response tells you which one you have.

  • The form shows an error such as “There was an error trying to send your message.” The status is mail_failed: WordPress could not hand the message to a mail transport at all. Step 5 tests wp_mail() on its own and prints the reason, such as SMTP connect() failed.
  • The form shows its green success message and nothing arrives. The status is mail_sent, which only means WordPress handed the message over. The usual cause is a From address that fails SPF or DMARC checks, so the receiving server drops the message. The fix is authenticated SMTP and correct DNS records for the sending domain, described in the troubleshooting section below and in WP Mail SMTP plugin setup.

Validate it works

A fix is proven when a real submission returns mail_sent and the message is visibly accepted by the mail transport. Both halves are required — the first without the second is exactly the failure mode that sends people looking for a form bug that is not there.

Run the submission end to end and read the status:

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-p1-o1' \
  -F 'your-name=Validation' -F 'your-email=test@example.com' \
  -F 'your-subject=Validation' -F 'your-message=Validation' \
  | grep -o '"status":"[a-z_]*"'

The expected output is "status":"mail_sent" and nothing else. Then prove the MTA accepted the message rather than trusting the plugin’s word for it:

grep -i 'you@example.com' /var/log/maillog | tail -5

A healthy line names a queue ID and a remote acceptance, for example to=<you@example.com>, relay=mx.example.net, dsn=2.0.0, status=sent (250 2.0.0 OK). status=bounced or status=deferred means the form is working and the mail path is not. On a host with no local MTA log, use the sending service’s own delivery log instead. Finally, submit once from a real browser in a private window and confirm the spinner stops and the green confirmation renders — that is the only test that exercises the cached page, the nonce, and the JavaScript together.

Troubleshooting

The REST route returns 404 or 403 for everyone. Security plugins commonly ship a “disable REST API” toggle that whitelists nothing, and hardened nginx configurations sometimes carry a location ~ ^/wp-json { deny all; } block copied from a blog post. Test by requesting /wp-json/ directly. If the root is also blocked, the fix belongs in the security plugin or the vhost, not in Contact Form 7 — and blanket-disabling REST breaks the block editor too.

A PHP fatal in a hook returns HTML instead of JSON. Code hooked to wpcf7_before_send_mail runs inside the REST request. If it throws, PHP prints an error page and the response body becomes HTML with a 200 status. The browser’s JSON.parse fails silently and the spinner never stops. Step 4 finds the fatal; the immediate fix is to disable the plugin that owns the hook, and the durable fix is to wrap that code so a failure aborts the mail cleanly instead of killing the request.

Page caching serves a stale nonce. The wp_rest nonce is printed into the page HTML and expires on a 24-hour tick. A full-page cache with a long TTL will happily serve a page whose nonce expired days ago. For logged-out visitors the feedback route is public, so the request still succeeds — but the request is no longer recognised as coming from that user, and plugins that gate on it will reject it. For logged-in editors testing the form, it fails outright. Exclude pages carrying forms from full-page caching, or shorten the TTL below the nonce lifetime.

wp_mail() returns true and the message still never arrives. This is the most common report behind “Contact Form 7 not sending email”, and it is not a Contact Form 7 problem at all. wp_mail() returning true means PHP handed the message to a transport, nothing more. If that transport is PHP’s mail() and the From address is on a domain whose SPF record does not list this server, receivers drop the message after accepting it. Route through authenticated SMTP, and set the From address to a real mailbox on your own domain rather than the visitor’s address. Diagnosing silent WordPress mail failures walks the delivery side in full.

mod_security or the WAF rejects the POST. Message bodies containing URLs, code snippets, or certain punctuation trigger generic rule sets, and the request is answered with a 403 — or, worse, held until the connection times out. The tell is that a submission with the text hello succeeds while the visitor’s real message fails. Find the rule ID in /var/log/modsec_audit.log, then whitelist that single ID for the feedback route. Turning the WAF off is not the fix.

When this is the wrong approach

Some of this is not worth debugging. If the site needs stored submissions, conditional fields, or multi-step forms, you are stacking four add-ons onto Contact Form 7 to reach what another plugin does natively — and each one hooks wpcf7_before_send_mail, the exact surface that produces the hanging spinner. Migrating to a form plugin with a database layer is the better answer; common WPForms issues covers that trade from the other side.

If the form is the only thing failing on a site where the REST API is otherwise fine, and the failure is intermittent rather than constant, stop looking at the form. Intermittent means resource exhaustion — PHP workers, memory, or an upstream timeout — and the form is simply the slowest request on the site because it waits on an SMTP handshake. Fix the capacity problem.

And if the submission works from curl but fails from every browser, the fault is in the page, not the plugin. That is a JavaScript problem: a console error from unrelated code, a bundler that combined the plugin’s script incorrectly, or two copies of the script on the page. Debugging WordPress AJAX errors covers the front-end half of that investigation.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.