Вопрос

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);

?>
Это было полезно?

Решение

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

Другие советы

Find script with CC and BCC 
$email = new \SendGrid\Mail\Mail();
$email->setFrom("test@example.com", "Example User");
$email->setSubject("Sending with Twilio SendGrid is Fun");
$email->addTo("test@example.com", "Example User");
$email->addCc("test@example.com", "Example User");
$email->addBcc("test@example.com", "Example User");
$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
$email->addContent(
    "text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
);
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
try {
    $response = $sendgrid->send($email);
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $e) {
    echo 'Caught exception: '. $e->getMessage() ."\n";
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top