The wpcf7_before_send_mail | wpcf7_mail_sent Hook


The wpcf7_mail_sent is a contact form 7 action hook. You can see more details on

How to get submission data from the wpcf7_mail_sent hook?

Add the following code in your theme functions.php or plugin file to get post data.

We can access data from the WPCF7_Submission class instance and get_posted_data method.

Best contact form 7 addons. Get it now

The wpcf7_mail_sent is not working

The wpcf7_mail_sent function will not work if the email function has any issues. We can solve the SMTP issue with the SMTP plugin. We can use the wpcf7_before_send_mail action hook if you want to hook before mail function execution.

The wpcf7_before_send_mail Hook Not Working

First deactivate contact form 7 related plugins from wp-admin > plugins. Then check chrome console log error.

Check $abort the variable is true in wpcf7_before_send_mail hook.

Best contact form 7 database plugin. Get it for free!

The wpcf7_before_send_mail Documentation

The wpcf7_before_send_mail hook triggers the before-send mail function. It can be used to save entries to the database.

Save submitted data to MySQL database columns by CF7ADB database plugin.


The wpcf7_before_send_mail get form id $form_id = $contact_form->id();

We can abort contact form 7 by assigning $abort = true;

The wpcf7_before_send_mail get post ID

Use global $post; The variable is the current custom post type or page post. Get post id by $post->ID;

More contact form 7 plugins. Get it now

The wpcf7_before_send_mail For Specific Form

Check the id of the form by if condition in a callback function.

Example : [contact-form-7 id="39" title="Contact form 1"] form id is 39.

The wpcf7_before_send_mail Get Form Data

We can access post data from $_POST variable.


Check chrome > network > check post request response.

How to save data to the database?

We can use this action hook and save by using $wpdb or MySQL functions or we can use the CFDB7 plugin or CF7ADB plugin. CF7ADB is easy to manipulate data.

How to Display Contact Form 7 Data in WordPress

Install CFDB7 or CF7ADB and display CFDB7 plugin. Then add shortcode [cfdb7-data form-id='{id}’]

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *