Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save khripunovpp/d103201e0fd03ed7892c05643b008678 to your computer and use it in GitHub Desktop.
Save khripunovpp/d103201e0fd03ed7892c05643b008678 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