Since WPCF7 5.2 the wpcf7_before_send_mail
hook has changed quite a lot. For reference, here is how to work with this hook in 5.2+
Skip mail
function my_skip_mail() {
return true; // true skips sending the email
}
add_filter('wpcf7_skip_mail','my_skip_mail');
Or add skip_mail
to the Additional Settings tab on your form in the admin area.
Getting the Form ID or Post ID
function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
$post_id = $submission->get_meta('container_post_id');
$form_id = $contact_form->id();
// do something
return $contact_form;
}
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );
Get user inputted data
function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
$your_name = $submission->get_posted_data('your-field-name');
// do something
return $contact_form;
}
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );
Send the email to a dynamic recipient
function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
$dynamic_email = 'email@email.com'; // get your email address...
$properties = $contact_form->get_properties();
$properties['mail']['recipient'] = $dynamic_email;
$contact_form->set_properties($properties);
return $contact_form;
}
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );