SendGrid不发送电子邮件,返回0数组([0] =>)

时间:2019-11-25 15:57:22

标签: php sendgrid http-status

我在PHP应用程序中使用SendGrid向我的用户发送电子邮件,以便他们可以重置其密码。事实是,在localhost上一切正常,但是当我将文件传输到服务器时,我得到了以下响应0 Array ( [0] => )。我在 Network 上进行检查时收到的状态码响应为200 OK,在SendGrid上,这表示您的消息有效,但未排队发送。。我不知道为什么会这样,有帮助吗?

$email = new SendGrid\Mail\Mail();
$email->setFrom("email@email.com", "Person");
$email->setSubject("Subject");
$email->addTo("email@email.com", "Person");
$email->addContent("text/plain", "This is the email.");
$email->addContent(
    "text/html",
    '<p>This is the email</p>'
);

$sendgrid = new \SendGrid('myKey');

try {
    $response = $sendgrid->send($email);
    print($response->statusCode());
} catch (Exception $e) {
    echo 'Caught exception: ' . $e->getMessage() . "\n";
}

1 个答案:

答案 0 :(得分:0)

您的主题行有误,缺少结尾处” $ email-> setSubject(“ Subject”);