Contact Form7

Hi,

Is there any way to add Bcc in Contact Form 7 with filter/hook? I know can be done with the additional headers but just wondering if this can be done with the code as well?

Thoughts?

Hi There,

Thanks for writing in! Regretfully, this particular customization request is outside the scope of our support as this is not related to an issue with the theme and instead has to do with your customization of it.

As you already know you can add CC & BCC in Additional Headers fields.

Adding Cc, Bcc and Other Mail Headers

Thank you for your understanding.

Hi,

Yeah, I understand that. I would highly appreciate that if you just point me out where to start with this.

Thanks in advance!

Hi There,

You can try with this code:


add_action('wpcf7_before_send_mail','dynamic_addcc');

function dynamic_addcc($WPCF7_ContactForm){

    // Check contact form id.
    if (12345 == $WPCF7_ContactForm->id()) {

        $currentformInstance  = WPCF7_ContactForm::get_current();
        $contactformsubmition = WPCF7_Submission::get_instance();

        if ($contactformsubmition) {

            $bcc_email = array('email1@example.com', 'email2@example.com', 'email3@example.com');

            // saparate all emails by comma.
            $cclist = implode(', ',$bcc_email);

            $data = $contactformsubmition->get_posted_data();

            if (empty($data))
                return;

            $mail = $currentformInstance->prop('mail');

            if(!empty($cclist)){
                $mail['additional_headers'] = "Bcc: $cclist";
            }

            // Save the email body
            $currentformInstance->set_properties(array(
                "mail" => $mail
            ));

            // return current cf7 instance
            return $currentformInstance;
        }
    }
}

Let us know how it goes!

Hi,

Thank you.

Was this code supposed to go in the child theme function.php file? I have added this and changed the email@example.com with my email but didn’t work. Can you check this, please?

Thanks

Got it, figured it out. Was missing the form ID. :grimacing:

Thanks a lot Thai.

Glad to hear we managed to help!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.