1

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

?>
Alex
  • 5,565
  • 6
  • 36
  • 57
user2720970
  • 284
  • 1
  • 3
  • 17

3 Answers3

3

Try this:

<?php
    $thirdMail = "three@example.com\r\n";
    $header = "From: email@example.com\r\n";
    $header .= "BCC: one@example.com,two@example.com,".$thirdMail;
    mail($toMail, $subject, $message, $header);
?>

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

wSkc
  • 149
  • 5
2

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: admin@website.com' . "\r\n";
$headers .= 'BCC: '. implode(",", $bcc) . "\r\n";

mail($to, $title, $content, $headers);
Manish Chauhan
  • 595
  • 2
  • 7
  • 14
2

Try this it may be useful for you:

<?php
$msgTo = "msgTo@email.com";
$msgSubject = "Mail Subject";
$msgContent = "This is the message,:)";

$bcc = "msgbcc@email.com";

$msgHeaders = "To: $msgTo\r\n";
$msgHeaders .= "From: no-reply@email.com\r\n";
$msgHeaders .= "Bcc: $bcc\r\n";
$msgHeaders .= "X-Mailer: PHP".phpversion();

$success = mail($msgTo, $msgSubject, $msgContent, $msgHeaders);?>
vinox
  • 401
  • 10
  • 22