Choose a Contact Form 7 PHP hook by the stage you need to observe. Use wpcf7_before_send_mail for work immediately before the mail stage, wpcf7_mail_sent for the successful mail branch, and wpcf7_mail_failed for the failed mail branch. None of these names establishes that a recipient read a notification or that an external service stored a lead.

This guide explains server-side lifecycle boundaries and a minimal observer for one form. It does not install a connector or change a live form. If your task is browser feedback or analytics after an AJAX submission, start with CF7 DOM events; PHP actions and browser events run in different environments.
Understand which submissions reach the mail stage
In the reviewed official submission handler, CF7 prepares the submission and evaluates validation, acceptance and spam outcomes before reaching mail processing. A callback attached before mail therefore does not observe every click on Submit. A field validation failure can stop the request earlier without invoking your mail-stage action.
The before-send action receives the form object, an abort flag by reference and the submission object. A callback can intentionally change that flag, which makes this a behavior-changing extension point. An observer should leave it alone. If another callback aborts processing, the request does not continue into the normal successful or failed mail branch.
After the mail routine returns, CF7 chooses its mail_sent or mail_failed branch and invokes the corresponding action with the form object. This ordering is useful when separating validation problems from transport problems. It is not a universal transaction boundary for every storage plugin or customization attached to the same submission.
Start with a narrowly scoped observer
Use a small site-specific plugin on staging or your approved snippet-management workflow. Replace the illustrative form ID 123 with the site’s actual numeric form record ID. Check that ID through the admin or a developer tool; do not assume a displayed hash-like shortcode identifier is the numeric ID used by id().
add_action( 'wpcf7_before_send_mail',
function ( $form, &$abort, $submission ) {
if ( 123 !== (int) $form->id() ) {
return;
}
// A staging observer only: no personal answers or mail changes.
error_log( 'CF7 form 123 reached before-send.' );
},
10,
3
);
add_action( 'wpcf7_mail_sent', function ( $form ) {
if ( 123 !== (int) $form->id() ) {
return;
}
error_log( 'CF7 form 123 reached mail-sent.' );
}, 10, 1 );
This example writes fixed diagnostic messages only. It does not log a visitor’s email, message, IP address or submitted payload, and it does not send an HTTP request. Check where the staging PHP error log is stored and who can read it before using even a simple observer. Remove the temporary observation once the question is answered.
The three accepted arguments in the first registration matter. Omitting them while expecting the submission and abort parameters is a common source of mismatched callbacks. The mail-sent action in this example requests only the form argument that the reviewed implementation passes to it.
Keep failure and abort outcomes separate
A failed mail branch means CF7’s mail routine returned failure. It does not describe every way a request can fail: invalid input, spam handling and an intentional abort are separate outcomes. Add a similarly scoped mail-failed observer when investigating that branch instead of using the absence of mail-sent as a complete error diagnosis.
For example, if before-send appears but neither ordinary mail outcome appears, review intentional abort behavior and callback errors. If before-send never appears, inspect earlier validation, acceptance and spam decisions. Use the WordPress debugging tool comparison to choose an appropriate inspection method without exposing logs on the public page.
Do not interpret mail-sent as inbox delivery
WordPress documents that a true return from wp_mail means the sending method processed the request without reporting an error; it does not prove receipt. CF7’s mail-sent branch inherits a sending-stage boundary. Later provider rejection, mailbox filtering or a downstream forwarding rule requires different evidence.
The reviewed CF7 mail routine also has a skip-mail path that returns success without sending mail. That is why a diagnostic observer can record the successful branch during a configured skip-mail scenario. Review demo and skip-mail behavior before using synthetic submissions to assess a custom callback. Record the active mode beside your observations.
Separate a callback from durable handoff
Running a callback once does not make an external operation durable. An HTTP request can time out, a response can be ambiguous, and the visitor can submit again. If the callback creates a downstream task or record, define how it obtains a stable operation identifier and how the destination prevents duplicates.
Do not put a slow sequence of retries directly in the visitor’s submission request. A considered design records an approved work item durably and lets a worker own delivery, retry limits and recovery. The webhook delivery comparison covers those architectural choices. Such a design needs an explicit data mapping and implementation; installing a reporting plugin does not create it automatically.
Also decide what should happen when the external system is unavailable. Preserving the enquiry, notifying the visitor and retrying a handoff are distinct decisions. A callback that changes the abort flag to handle a remote failure can alter the visitor’s result, so review that behavior deliberately rather than borrowing a snippet without understanding its consequences.
Verify on staging and keep a version note
Use synthetic submissions to cover valid input, invalid input, a controlled mail failure and any intentionally configured skip or abort path. Record the expected observer sequence before running the checks. Confirm that an unrelated form generates no scoped observer messages. These are suggested checks, not tests performed on this site’s live forms.
Keep the installed CF7 version and callback owner in the implementation notes. The linked upstream source was reviewed on October 16, 2026, but a moving repository branch is not a version guarantee for your installation. Recheck signatures and ordering when maintaining custom code.
For reporting alongside an integration, review the free Svetlik Analytics for Contact Form 7 listing. This site publishes that product. Treat its documented reporting as one observation layer, with delivery and downstream record creation verified separately.
