PHP form send email to multiple recipients

后端 未结 7 1892
無奈伤痛
無奈伤痛 2020-11-27 05:18

I have some PHP code that I\'m using to send a form off to a specific e-mail address. However, I\'d like to include a couple more e-mail addresses in the PHP for when it sen

相关标签:
7条回答
  • 2020-11-27 05:23

    If these all answers are not working then You can simply use multiple mail function for multiple recipient.

    $email_to1 = "firstEmail@demo.com";
    $email_to2 = "secondEmail@demo.com";
    
    mail($email_to1, $email_subject, $email_message, $headers);  
    mail($email_to2, $email_subject, $email_message, $headers);  
    
    0 讨论(0)
  • 2020-11-27 05:36

    If you need to add emails as CC or BCC, add the following part in the variable you use as for your header :

    $headers .= "CC: sombodyelse@noplace.com".PHP_EOL;
    $headers .= "BCC: hidden@special.com".PHP_EOL;
    

    Regards

    0 讨论(0)
  • 2020-11-27 05:36

    You can add your receipients to $email_to variable separating them with comma (,). Or you can add new fields to headers, namely CC: or BCC: and put your receipients there. BCC is most recommended

    0 讨论(0)
  • 2020-11-27 05:37

    This will work:

    $email_to = "jhewitt@amleo.com,some@other.com,yet@another.net";
    
    0 讨论(0)
  • 2020-11-27 05:39

    Use comma separated values as below.

    $email_to = 'Mary <mary@example.com>, Kelly <kelly@example.com>';
    @mail($email_to, $email_subject, $email_message, $headers);
    

    or run a foreach for email address

    //list of emails in array format and each one will see their own to email address
    $arrEmail = array('Mary <mary@example.com>', 'Kelly <kelly@example.com>');
    
    foreach($arrEmail as $key => $email_to)
        @mail($email_to, $email_subject, $email_message, $headers);
    
    0 讨论(0)
  • 2020-11-27 05:40

    If i understood correct try this one

    $headers = "Bcc: someone@domain.com";
    

    or

    $headers = "Cc: someone@domain.com";
    
    0 讨论(0)
提交回复
热议问题