1

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

$to = 'abc@xyz.com';
$subject = 'Order Details of Order Number:'.$orderID; 
$headers = "From: webmaster@xyz.com\r\nReply-To: webmaster@xyz.com";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; 
$message = "Test Message";
$headers .= 'Cc: def@xyz.com' . "\r\n";
mail($to, $subject, $message, $headers);

I am sending this mail as HTML.

Laurel
  • 5,965
  • 14
  • 31
  • 57
Rajesh
  • 195
  • 1
  • 2
  • 15
  • Try adding "\r\n" before cc string: $headers .= "\r\n" . 'Cc: def@xyz.com' . "\r\n"; – Gale Mar 22 '16 at 10:38

2 Answers2

1

Add the header as following,

$to = 'toemailaddress@testcom';
$from = 'fromemail@from.com';
$fromName = 'FromName';
$subject = "Email Subject";
$htmlContent = "<h> content of the email </h>";
$headers = "From: $fromName" . " <" . $from . ">" . "\r\n";
$headers .= "Cc: cc@cc.com ";
$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);
Varun P V
  • 1,092
  • 1
  • 12
  • 30
0

Try add this code in the following order:

$headers = "From: $from_email\r\nReply-To: $from_email";
$headers .= 'Cc: test@test.com\r\n';
$headers .= 'Bcc: test@test.com\r\n';
$headers .= "Return-Path: <info@premierinspectiontn.com>\r\n";

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

Resource

Community
  • 1
  • 1
NormundsP
  • 445
  • 2
  • 7
  • 16
  • I tried your code, it sends only to main recipient, that too in junk and not in html format – Rajesh Mar 22 '16 at 10:45
  • If i use the content-type alternate instead of mixed, it sends to inbox and in html format but cc is not working $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; – Rajesh Mar 22 '16 at 10:48