Send email with CC copy and BCC hidden recipients - PHP

How to send an email with added recipients in copy and hidden copy, using PHP ? Can you please give me suggestion how can I add CC and BCC recipients to an email message ?
posted on 20.10.2019 at 18:24
0pnshow more
onefiveonefive
Hi,

To send an email to recipients in copy and to recipients in hidden copy, you can use the solution below. The main recipient has to be added directly to PHP mail() function. Copy recipients or Hidden copy recipients have to be included in additional headers.


$sender = "sender@example.com";
$sendername = "Name Surname";
$recipient = "main.recipient@example.com";
$copyrecipient = "copy.recipient@example.com";
$hiddencopyrecipient = "hiddencopy.recipient@example.com";

$subject = "Email subject";
$content = "Text or HTML content";

$headers = "From: " . $sendername . " <" . $sender . ">\n" ;
$headers .= "Cc: " . $copyrecipient . "\nBcc: " . $hiddencopyrecipient . "\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$headers .= "Return-Path: " . $sender . "\n";
$headers .= "X-Mailer: PHP/" . phpversion();

$send = mail($recipient, $subject, $content, $headers);

if ($send) { echo "Email sent"; } else { echo "Email not sent"; }
posted on 08.11.2019 at 10:45
0pnshow more
TimTim
share on facebookshare on twitter
2020 AnswerTabsTermsContact us
This site uses cookies to improve your experience, for analytics and ads. By continuing to browse this site you agree to our use of cookies.