9

我将 sendgrid 与 php 一起使用,我使用了客户端库和 curl 选项这两个选项。到目前为止,我已经能够毫无问题地使用 addTo 选项直接发送电子邮件。但是当我尝试添加抄送或密件抄送选项时,电子邮件仍会发送,但副本从未送达。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);

?>
4

2 回答 2

15

该文档似乎没有 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

于 2014-04-08T21:33:07.770 回答
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";
}
于 2021-08-06T13:30:17.817 回答