phpsendgridbcccarbon-copy

SendGrid Cc and Bcc not working on PHP


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("mymail@gmail.com");
$mail ->addCc("other@otherserver.com");
$mail ->setFrom("sender@server.com");
$mail ->setSubject("TEST");
$mail->setHtml("<h1>Example</h1>");
$sendgrid->send($mail);

?>

Solution

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

    $mail = new SendGrid\Email();
    $mail->addTo('foo@bar.com')->
           addTo('someotheraddress@bar.com')->
           addTo('another@another.com');
    

    or

    $mail   = new SendGrid\Email();
    $mail->addBcc('foo@bar.com');
    $sendgrid->send($mail);
    

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