The wpcf7_mail_sent Contact Form 7 Action Hook


wpcf7_mail_sent

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

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.

The wpcf7_mail_sent is not working

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

The wpcf7_before_send_mail Example

The wpcf7_before_send_mail get post ID

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

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.

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 *