PHP Mailer, need to add multiple Bcc

user2720970 picture user2720970 · Aug 27, 2013 · Viewed 11.8k times · Source

I have been using this mailer for a while, but now I need to add (multiple) permanent Bcc addresses. How can I do this?

Here is my code so far:

<?php

$message = '';

if (isset($_POST['email']) && !empty($_POST['email'])) {
    if (mail($_POST['email'], $_POST['subject'], $_POST['body'], "From: me@mydomain")) {
        $message = "Email has been sent to <b>".$_POST['email']."</b>.<br>";
    } else {
        $message = "Failed sending message to <b>".$_POST['email']."</b>.<br>";
    }
} else {
    if (isset($_POST['submit'])) { 
        $message = "No email address specified!<br>";
    }
} 

if (!empty($message)) {
    $message .= "<br><br>";
}

?>

Answer

wSkc picture wSkc · Aug 27, 2013

Try this:

<?php
    $thirdMail = "[email protected]\r\n";
    $header = "From: [email protected]\r\n";
    $header .= "BCC: [email protected],[email protected],".$thirdMail;
    mail($toMail, $subject, $message, $header);
?>

As you can see, each adress is seperated by a comma.