1

I have a PHP script that automatically send outs an email. I have it working great, but when I try to add a CC, it doesn't work. Below is my code for the email to:

$email_to = "$theData2"; // Who the email is to 

$headers = "From: ".$email_from; 

$ok = @mail($email_to, $email_subject, $email_message, $headers);

I have tried the following to get CC to work, but I haven't had any luck.

$email_cc = "example@info.com"; 
$headers .= "CC: ".$email_cc;

and also have tried this:

$headers .= "CC: sombodyelse@noplace.com";

I can't get it to email to both the: to & cc.

Any help would be greatly appreciated. Thanks!

Mat
  • 202,337
  • 40
  • 393
  • 406
John
  • 11
  • 1
  • 1
    Don't use PHPs `mail()` function directly. It is much easier and safer to use a library such as PHPMailer or SwiftMailer. – Treffynnon Mar 28 '11 at 13:51

4 Answers4

2

You forgot your newline.

$headers .= "\r\nCc: ".$email_cc;
awm
  • 6,526
  • 25
  • 24
2

Try ending your header entries with "\r\n":

$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";
Nathan Arthur
  • 8,287
  • 7
  • 55
  • 80
sreimer
  • 4,913
  • 2
  • 33
  • 43
1

Have you tried with "Cc" and not "CC" ? And do not forget the "\n" at the end.

Raveline
  • 2,660
  • 1
  • 24
  • 28
1

Don't use PHPs mail() function directly. Use a wrapper class such as SwiftMailer or PHPMailer. They give you far more flexibility and are safer.

Treffynnon
  • 21,365
  • 6
  • 65
  • 98