SendGrid Cc and Bcc not working on PHP

Mike picture Mike · Apr 8, 2014 · Viewed 10.6k times · Source

I'm using sendgrid with php, I've used both options the client library and the curl option. So far, I've been able to send emails directly with the addTo option with no problem. But when I try to add Cc or Bcc options, the email still gets sent but the copies are never delivered. Are there any known issues with the php version? In other project the java library works just fine.

Here is a simple piece of code I'm trying to make it work

<?php
require ('sendgrid/sendgrid-php.php');

$sendgrid = new SendGrid('user', 'pwd');

$mail = new SendGrid\Email();
$mail ->addTo("[email protected]");
$mail ->addCc("[email protected]");
$mail ->setFrom("[email protected]");
$mail ->setSubject("TEST");
$mail->setHtml("<h1>Example</h1>");
$sendgrid->send($mail);

?>

Answer

user2616876 picture user2616876 · Apr 8, 2014

The documentation does not seem to have addCc method. You can try these alternatives.

$mail = new SendGrid\Email();
$mail->addTo('[email protected]')->
       addTo('[email protected]')->
       addTo('[email protected]');

or

$mail   = new SendGrid\Email();
$mail->addBcc('[email protected]');
$sendgrid->send($mail);

https://github.com/sendgrid/sendgrid-php#bcc