SendGrid Cc和Bcc不适用于PHP

时间:2014-04-08 21:18:02

标签: php sendgrid bcc carbon-copy

我正在使用带有php的sendgrid,我已经使用了客户端库和curl选项这两个选项。到目前为止,我已经能够直接使用addTo选项发送电子邮件,没有任何问题。但是当我尝试添加Cc或Bcc选项时,电子邮件仍然会被发送,但副本永远不会被发送。 php版本有任何已知问题吗?在其他项目中,java库工作正常。

这是一段我正在尝试使其正常工作的简单代码

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

?>

2 个答案:

答案 0 :(得分:10)

文档似乎没有addCc方法。 您可以尝试这些替代方案。

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

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

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

答案 1 :(得分:0)

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";
}