Viewing 9 replies - 1 through 9 (of 9 total)
  • This is possible using the pipes code… see: https://contactform7.com/selectable-recipient-with-pipes/

    If this doesn’t work, you may need to create a new action:
    add_action('wpcf7_before_send_mail', 'custom_wpcf7_before_send_mail');

    and handle recipients here based on conditions from form post. Example:

    add_action('wpcf7_before_send_mail', 'custom_wpcf7_before_send_mail');
    function custom_wpcf7_before_send_mail($form) {
        $wpcf7 = WPCF7_ContactForm::get_current();
        $submission = WPCF7_Submission::get_instance();
        $data = $submission->get_posted_data();
    
        if(empty($data)) return;
    
        // assuming this is a post of an array of CHECKBOXES -- named "recipients" with email addresses of values. NOTE: See NOTE, below code.
        $recipients = isset($data['recipients']) ? $data['recipients'] : false;
    
        $recipientsList = array();
        if($recipients) {
          foreach($recipients as $recipient) {
            $recipientsList[] = $recipient;
          }
        }
    
        $mail = $wpcf7->prop('mail');
        $mail['recipient'] = implode(",", $recipientsList);
        $wpcf7->set_properties(array("mail" => $mail));
    
        return $wpcf7;
    }

    NOTE: I highly suggest against using email addresses in values of HTML elements due to web scrapers/spammers. Instead, use something else like ID #’s or names, then reference them back in your code and then setup the recipients.

    Thread Starter bilslandlewis

    (@bilslandlewis)

    Hi Rob finally got round to trying this, all works perfectly using pipes method except other recipients can see who the emails have been sent to.

    Is there a way they can be sent with the other email addresses hidden?

    The full list of choices a user can select from will be as many as 19, they can select up to 3 to send an email to.

    When the email comes through ideally that reader will only see it was sent to them

    Use bcc in your additional mail headers.

    Thread Starter bilslandlewis

    (@bilslandlewis)

    each email address is still displayed in the receiving inbox

    i have this in the form:

    <label>Select up to 3 recipients</label>
    [select* your-recipient multiple
    "Email one|one@test.com"
    "Email two|two@test.com"
    "Email three|three@test.com"
    "Email four|four@test.com"]

    then within additional headers I have:

    Bcc:one@test.com
    Bcc:two@test.com
    Bcc:three@test.com
    Bcc:four@test.com

    The email arrives in the recipient inbox and the selection of email addresses made from the dropdown are always displayed

    Your “TO” field needs to be to something… like a no-reply@email address.

    Your BCC emails are never seen in emails.. so perhaps you have a form misconfigured?

    Also, make sure you’re using the proper template tags.

    Thread Starter bilslandlewis

    (@bilslandlewis)

    I’m not sure what could be wrong, this is my form code

    <label>First name(required)</label>
        [text* first-name] 
    
    <label>Last name(required)</label>
        [text* last-name] 
    
    <label>Your Email (required)</label>
        [email* your-email] 
    
    <label>Select up to 3 recipients</label>
    [select* your-recipient multiple
    "Email one|one@test.com"
    "Email two|two@test.com"
    "Email three|three@test.com"
    "Email four|four@test.com"]
    
    <label>Your Message</label>
        [textarea your-message]
    
    <label>Enter the message as it's shown</label>
        [captchac captcha-188 size:m]<br />
        [captchar captcha-188]
    
    <p>[submit "Send"]</p>

    then in additional headers:

    Bcc:[one@test.com], [two@test.com],[three@test.com],[four@test.com]

    in the to field I have no-reply@test.com

    Not sure what could be going wrong with this?

    So you’re seeing those email addresses in the body of the email? To get the email address you use [your-recipient]. To get the label value, such as “email one”, you need to use [_raw_your-recipient]

    Does this help?

    Thread Starter bilslandlewis

    (@bilslandlewis)

    Hi Rob
    Thanks for your help on this, I have changed my ‘to’ field to [your-recipient] and the email comes through to my test address, but the problem is not that I see the emails in the body, it’s that I still see the other email addresses in the ‘to’ field when it arrives in the inbox.

    So using bcc does not seem to work

    If a reader of the site selects 2 out of the 4 email addresses from the dropdown that works perfectly, the problem is that when the email comes through to email user 1 they can also see it has been sent to email user 2

    Thread Starter bilslandlewis

    (@bilslandlewis)

    Using pipes to select multiple works perfectly, but this is flawed as bcc does not work, adding the addresses to additional headers results in all emails being sent to all users through bcc.

    Additional headers overrides the multiple selections the user would make.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Send to up to 3 recipients’ is closed to new replies.