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 ?
0
give a positive ratinggive a negative rating
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"; }
Share on FacebookShare on TwitterShare on LinkedInSend email
1 answer
x
x
2024 AnswerTabsTermsContact us