PHP Mailer, need to add multiple Bcc

12.8k views Asked by At

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>";
}

?>
3

There are 3 answers

0
wSkc On

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.

0
Manish Chauhan On

See here, this will provide details which can help to set cc and bcc in mail().

e.g,

$bcc = array_of_bcc_users;
$headers = 'From: [email protected]' . "\r\n";
$headers .= 'BCC: '. implode(",", $bcc) . "\r\n";

mail($to, $title, $content, $headers);
0
vinox On

Try this it may be useful for you:

<?php
$msgTo = "[email protected]";
$msgSubject = "Mail Subject";
$msgContent = "This is the message,:)";

$bcc = "[email protected]";

$msgHeaders = "To: $msgTo\r\n";
$msgHeaders .= "From: [email protected]\r\n";
$msgHeaders .= "Bcc: $bcc\r\n";
$msgHeaders .= "X-Mailer: PHP".phpversion();

$success = mail($msgTo, $msgSubject, $msgContent, $msgHeaders);?>