Hello @spuri123,
You can use the wpcf7_before_send_mail hook.
add_action('wpcf7_before_send_mail','dynamic_addheaders');
function dynamic_addheaders( $WPCF7_ContactForm ) {
// Check contact form id.
if ( [YOUR-CONTACT-FORMID] == $WPCF7_ContactForm->id() ) {
$currentformInstance = WPCF7_ContactForm::get_current();
$contactformsubmition = WPCF7_Submission::get_instance();
if ( $contactformsubmition ) {
$mail = $currentformInstance->prop('mail');
$cc_email = array();
if( $_POST['menu-820'] == 'Distillery Enquiry' ) {
$cc_email = array( '[email protected]', '[email protected]' );
} elseif ( $_POST['menu-820'] == 'Product Enquiry' ) {
$cc_email = array( '[email protected]' );
} elseif ( $_POST['menu-820'] == 'Trade Enquiry' ) {
$cc_email = array( '[email protected]' );
}
if( !empty($cc_email) ) {
// saparate all emails by comma.
$cclist = implode(', ',$cc_email);
if(!empty($cclist)){
$mail['additional_headers'] = "Cc: $cclist";
}
}
// Save the email body
$currentformInstance->set_properties(array(
"mail" => $mail
));
// return current cf7 instance
return $currentformInstance;
}
}
}
Hi Jainil nagar,
Thanks for that. Might be a silly question, where do I add this code/
Thanks and Regards,
Siddharth Puri
-
This reply was modified 6 years, 3 months ago by
spuri123.
Hello @spuri123,
Add this code in your theme’s functions.php file.
Hi, I added it there. However, it did not work. still not sending emails to the second email.