【问题标题】:SendGrid Cc and Bcc not working on PHPSendGrid Cc 和 Bcc 在 PHP 上不起作用
【发布时间】:2014-05-21 19:39:16
【问题描述】:

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

?>

【问题讨论】:

  • var_dump($mail) 并发布输出

标签: php sendgrid bcc carbon-copy


【解决方案1】:

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

【讨论】:

  • Multiple addTo 可以模仿密件抄送,但是我需要将电子邮件与它们各自的抄送和密件抄送一起发送。 addCc 方法没有出现在文档中,但出现在库中。
  • 他们已经从文档中删除了 addCc。 github.com/sendgrid/sendgrid-php/commit/…
  • 您也可以在此处查看此问题。 github.com/sendgrid/sendgrid-php/issues/83
  • 这绝对是个好消息。谢谢,我想我会为此采用 phpMailer 方法
【解决方案2】:
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";
}

【讨论】:

    猜你喜欢
    • 2013-04-05
    • 2012-09-01
    • 2011-09-12
    • 2021-05-03
    • 1970-01-01
    • 2013-01-19
    • 2014-05-01
    • 1970-01-01
    • 2013-10-11
    相关资源
    最近更新 更多