Adding CC in PHP mail function

2.9k views Asked by At

I want to send mail with CC. The email is sent successfully, but CC is not sent.

$to = '[email protected]';
$subject = 'Order Details of Order Number:'.$orderID; 
$headers = "From: [email protected]\r\nReply-To: [email protected]";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; 
$message = "Test Message";
$headers .= 'Cc: [email protected]' . "\r\n";
mail($to, $subject, $message, $headers);

I am sending this mail as HTML.

2

There are 2 answers

2
NormundsP On

Try add this code in the following order:

$headers = "From: $from_email\r\nReply-To: $from_email";
$headers .= 'Cc: [email protected]\r\n';
$headers .= 'Bcc: [email protected]\r\n';
$headers .= "Return-Path: <[email protected]>\r\n";

//add boundary string and mime type specification
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

Resource

0
Varun P V On

Add the header as following,

$to = 'toemailaddress@testcom';
$from = '[email protected]';
$fromName = 'FromName';
$subject = "Email Subject";
$htmlContent = "<h> content of the email </h>";
$headers = "From: $fromName" . " <" . $from . ">" . "\r\n";
$headers .= "Cc: [email protected] ";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
//multipart boundary 
$message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" ."Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n";
$returnpath = "-f" . $from;
$message .= "--{$mime_boundary}--";
$mail = @mail($to, $subject, $message, $headers, $returnpath);