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
20 Oct 2019 at 06:24 PM
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"; }
0
give a positive ratinggive a negative rating
08 Nov 2019 at 10:45 AM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
2024 AnswerTabsTermsContact us