Skip to content

Instantly share code, notes, and snippets.

@mathiasmadsen
Created March 23, 2017 13:39
Show Gist options
  • Save mathiasmadsen/afd06d5380f74c080fb104ac5fd6eaea to your computer and use it in GitHub Desktop.
Save mathiasmadsen/afd06d5380f74c080fb104ac5fd6eaea to your computer and use it in GitHub Desktop.
// Send copy, if radio checked – Based on http://www.motomax.de/wordpress/contact-form-7-send-copy-to-sender-with-checkbox-in-3-9-update/
function check_mail_send_contactform($cf7) {
//get CF7's mail and posted_data objects
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
}
$mail = $cf7->prop( 'mail' );
if(isset($posted_data['checkbox'][0])) { //if Checkbox checked
$mail2 = $cf7->prop( 'mail_2' ); //get CF7's mail_2 object
//now set sender's address to mail2's recipient
$mail2['recipient'] = $posted_data['your-email'];
$cf7->set_properties( array( 'mail_2' => $mail2 ) );
}
return $cf7;
}
add_action('wpcf7_before_send_mail','check_mail_send_contactform');
@johnzuh
Copy link

johnzuh commented Jan 11, 2021

This did it for me too if(isset($posted_data['contact_sendmail'][0]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment