Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jose-serrao/6d9c3094c51cc94de1b622c645dca3ed to your computer and use it in GitHub Desktop.
Save jose-serrao/6d9c3094c51cc94de1b622c645dca3ed to your computer and use it in GitHub Desktop.
1. Open the CF7 contact form which you want to edit in wordpress Admin area. You set up the [checkbox] snippet which produces the checkbox in the contact form on your website:
[checkbox contact_sendmail "Send me a copy of this message"]
2. Activate Mail(2)
3. Add to functions.php
function check_mail_send_contactform($cf7)
{
$submission = WPCF7_Submission::get_instance();
if ( $submission )
{
$posted_data = $submission->get_posted_data();
}
$mail = $cf7->prop( 'mail' );
if(!empty($posted_data['contact_sendmail'][0]))
{
$mail2 = $cf7->prop( 'mail_2' );
$mail2['recipient'] = $posted_data['your-email'];
$cf7->set_properties( array( 'mail_2' => $mail2 ) );
}
else {
$cf7->set_properties( array( 'mail_2' => array() ));
}
return $cf7;
}
add_action('wpcf7_before_send_mail','check_mail_send_contactform');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment