PHP send email BCC & CC using SMTP

Viewed 9387

I have an PHP code to send email to, cc & bcc.

In this case, the cc is not working. I tested it and saw on my email there is no cc email. (BCC email is worked)

Here is my code:

require_once "Mail.php";

$from = "WEBAPPS <donotreply@test.com>";
$subject = "Calibration will be expiring!";

$host = 'smtp.office365.com';
$port = '587';
$username = 'donotreply@test';
$password = 'w00ew?';

$to = "alwis.david@gmail.com";
$cc = "data.gw@gmail.com";
$bcc = "hidayurie.dave@yahoo.com";

$body = "aa";

$headers = array(
'Port'          => $port,
'From'          => $from,
'To'            => $to,
'Subject'       => $subject,
'Content-Type'  => 'text/html; charset=UTF-8'
);

$recipients = $to.", ".$cc.", ".$bcc;

$smtp = Mail::factory('smtp',
array ('host' => $host,
 'auth' => true,
 'username' => $username,
 'password' => $password));

$mail = $smtp->send($recipients, $headers, $body);

if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
} else {
   echo("<p>Message successfully sent!</p>");
}

Why CC is not working? and how to solve it?

2 Answers
Related