I have a plugin I am writing that I want to interact with Contact Form 7. In my plugin I added the following action add_action
add_action(\"wpcf7_before_send
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+
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.
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 );
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 );
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 );