简体   繁体   中英

php mail function: Sending mails to BCC only

the first param of php mail function is TO. Is there anyway to skip this parameter and use only CC/BCC to send bulk mails?

Thanks

An email message does not require a To header field . So you could pass null or a blank string for the to parameter, set up your own header containing the BCC header field and provide it with the fourth parameter additional_headers of mail :

$headerFields = array(
    'BCC: user1@example.com, user2@example.com, user3@example.com'
);
mail(null, $subject, $message, implode("\r\n", $headerFields));

You can specify fourth headers parameter for that like this:

    $xheaders = "";
    $xheaders .= "From: <$from>\n";
    $xheaders .= "X-Sender: <$from>\n";
    $xheaders .= "X-Mailer: PHP\n"; // mailer
    $xheaders .= "X-Priority: 1\n"; //1 Urgent Message, 3 Normal
    $xheaders .= "Content-Type:text/html; charset=\"iso-8859-1\"\n";
    $xheaders .= "Bcc:email@example.com"\n";
    $xheaders .= "Cc:email2@example.com\n";

    //.......

    mail($to, $subject, $msg, $xheaders);

In the $to field you can specify your email or whatever you like.

Note that you can also specify multiple email addresses by separating them with a comma although I am not sure about exact number of email you can specify this way.

您可以在To标头中放置自己的电子邮件地址或其他虚拟地址,并将所有收件人地址放在Bcc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM