• Resolved spuri123

    (@spuri123)


    Hi, I have created conditional mail group using-
    <label> Enquiry Type
    [select* menu-820 include_blank “Distillery Enquiry|[email protected]” “Product Enquiry|[email protected]” “Trade Enquiry|[email protected]”] </label>

    and it works.

    Now, I want to add 2 or 3 emails as CC in each enquiry type and so on –

    What would be the code for that?

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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;
    	}
        }
    }
    
    Thread Starter spuri123

    (@spuri123)

    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.

    Thread Starter spuri123

    (@spuri123)

    Hi, I added it there. However, it did not work. still not sending emails to the second email.

    Thread Starter spuri123

    (@spuri123)

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Multiple emails in conditional email’ is closed to new replies.