Volatil3
Volatil3

Reputation: 14978

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

Upvotes: 9

Views: 25174

Answers (3)

Gumbo
Gumbo

Reputation: 655239

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: [email protected], [email protected], [email protected]'
);
mail(null, $subject, $message, implode("\r\n", $headerFields));

Upvotes: 15

Fahad Sadah
Fahad Sadah

Reputation: 2418

You can put your own email address, or another dummy, in the To header, and put all the recipient addresses in Bcc.

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382696

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 protected]"\n";
    $xheaders .= "Cc:[email protected]\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.

Upvotes: 13

Related Questions