Execute a function before mail function fire on Contact Form 7

Contact Form 7 is one of the most popular form management plugins available on WordPress repository. Which provide user friendly interface for managing form and email body. We can also manage addition settings like success or failure message form redirection etc in plugin settings.

Sometimes you will need some extra functions with POST values which will be executed before sending the mail then you need to add below code on your theme’s functions.php file, adding the wpcf7_before_send_mail hook as an add_action call.

add_action( 'wpcf7_before_send_mail', 'your_custom_function' );
function your_custom_function($cf7) {
   $output = "";
   $output .= "Name: " . $_POST['your-name'];
   $output .= "Email: " . $_POST['your-email'];
   $output .= "Company name: " . $_POST['com-name'];
  echo $output;
}

In this example, I have displayed the POST values.You can do what you need.

Please follow and like us:

Leave a Reply

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