We are running a competition whereby we need to send emails out to email addresses that are entered on a form. I'm using Contact Form 7 to do this.

I thought this would be straightforward but the form will not accept the syntax of:

[friend1-email], [friend2-email], [friend3-email], [friend4-email], [friend5-email]

In the To or Bcc field.

I think the solution might be to just hard-code a value in the To field and then override it with a hook, but I can't work out what that filter/hook might be.

Any help appreciated.


1 Answer 1


No need to write any code, Contact form 7 has features of Additional Headers in the Mail section. In that you just need to write the email's header inside the Additional headers textbox in Mail(Second Tab) section.

Put this inside the Additional Headers textbox.

Cc: [friend1-email], [friend2-email], [friend3-email], [friend4-email], [friend5-email]

enter image description here


You can alter the email header data by hooks wpcf7_before_send_mail try below code.


function dynamic_addcc($WPCF7_ContactForm){

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

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

        if ($contactformsubmition) {

            $cc_email = array();

            /* -------------- */
            // replace with your email field's names
                array_push($cc_email, $_POST['friend1-email']);
                array_push($cc_email, $_POST['friend2-email']);
            /* -------------- */

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

            $data = $contactformsubmition->get_posted_data();

            if (empty($data))

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

                $mail['additional_headers'] = "Cc: $cclist";

            // Save the email body
                "mail" => $mail

            // return current cf7 instance
            return $currentformInstance;

wpcf7_before_send_mail hook runs before email send, you can modify the form data.

  • This results in a syntax error
    – mikemike
    Commented Dec 7, 2016 at 9:06
  • make as required those all email fields, @mikemike
    – GKS
    Commented Dec 7, 2016 at 9:14
  • But they arent required :(
    – mikemike
    Commented Dec 7, 2016 at 9:15
  • all email inside Cc: should be present otherwise it will through error,
    – GKS
    Commented Dec 7, 2016 at 9:19
  • 1
    @mikemike I have updated my answer , replace with your contact form id and field's name.
    – GKS
    Commented Dec 7, 2016 at 10:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.