PHP Email Sending Bcc

PHP Email sending BCC

You have $headers .= '...'; followed by $headers = '...';; the second line is overwriting the first.

Just put the $headers .= "Bcc: $emailList\r\n"; say after the Content-type line and it should be fine.

On a side note, the To is generally required; mail servers might mark your message as spam otherwise.

$headers  = "From: no-reply@thepartyfinder.co.uk\r\n" .
"X-Mailer: php\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Bcc: $emailList\r\n";

PHP Mail adding BCC

You should concatenate $headers

Example :

$headers  = "From: *****@etrackbureau.co.za\r\nX-Mailer: php\r\n";
$headers .= "MIME-Version: 1.0\r\n"; #Define MIME Version
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; #Set content type
$headers .= "Bcc: $EmailListHere\r\n"; #Your BCC Mail List

PHP send email BCC & CC using SMTP

The carbon copy is an header.
All recipients are recipients in the same way for the mail server, the difference between carbon copy and blind carbon copy is just a matter of declaring it in the headers.

$headers = array(
'Port' => $port,
'From' => $from,
'To' => $to,
'Subject' => $subject,
'Content-Type' => 'text/html; charset=UTF-8',
'Cc' => $cc
);

php mail function: Sending mails to BCC only

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.

Sending PHP email copies internally (with BCC)

It seems that here: $to = $email. and here: $bcc = "sales@example.com". shouldn't be a following dots, but a semicolons. To send to Bcc you have to add one more header like this: $headers .= "Bcc: somebodyelse@example.com\r\n";

And here should be a semicolon in the end instead of the dot:

$email_body = "Hello,\n $name.\n".
"Your order number is:\n $order".
"Your order was placed on:\n $date".
"Your total cost is:\n $cost".
"Your tracking number is:\n $tracking".
"You can track your order on our website.\n".
"Thanks,\n examplecompany \n".

So below you can see the working code:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$order = $_POST['order'];
$date = $_POST['date'];
$cost = $_POST['cost'];
$tracking = $_POST['tracking'];

$email_from = "noreply@example.com";

$email_subject = "Your order details";

$email_body = "Hello,\n $name.\n".
"Your order number is:\n $order".
"Your order was placed on:\n $date".
"Your total cost is:\n $cost".
"Your tracking number is:\n $tracking".
"You can track your order on our website.\n".
"Thanks,\n examplecompany \n";

$to = $email;
$headers = "From: noreply@example.com \r\n";
$headers .= "Bcc: sales@example.com \r\n";
$headers .= "Reply-To: constact@example.com \r\n";

mail($to, $email_subject, $email_body, $headers);

?>

UDATE:
To include variables in PHP string, you need to use double quotes " instead of single ones '. But in this case you need to escape any double quotes that neccesary for your HTML code, to do this you have to put back slash before a double quote, like thhis: \". So below is the working code for your PHP string with HTML tags:

$email_body = " 
<body>
<div>
Hello, $name<br><br>
Your order number is: <strong> $order</strong><br>
Your order was placed on: <strong> $date</strong><br>
Your total cost is: <strong>£ $cost</strong><br>
Your tracking number is: <strong> $tracking</strong><br>
You can track your order on our website <a href=\"https://example.com/track\">here</a>.<br><br>
Thanks,<br>examplecompany.<br>
<a href=\"https://example.com\"><img src=\"https://example/assets/images/logo.png\" alt=\"examplecompany logo\" width=\"200px\"></a>
</div>";

Add bcc PHP mail function

You would add this in the headers:

'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'Bcc: someone@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

As shown on the docs at PHP.net

Add Bcc to email sent with Gmail API with PHP

To anyone else who thinks he is facing the same problem, just let me tell you there is no problem, everything is working fine.

The code works properly, BUT if you are doing like I did, and you are using your Gmail account to send the emails and including yourself in the recipients, when you get the email, you can see the Bcc list as the email came from your account.

I only figured this out after @ficuscr asked his question in the comments and I went to confirm with the "to" recipient if he could see the Bcc recipients, he couldn't, nor did the other Bcc recipients.

I hope this helps someone to save a few hours of research.



Related Topics



Leave a reply



Submit