如何使用Sendgrid发送邮件,我已经尝试了很多次,但是给出了错误信息,
找不到类之类的错误,我也已经安装了作曲家,但我听不懂,请给我解决方案
错误图片:
require './vendor/autoload.php';
include_once('credentials.php');
$FROM_EMAIL = 'from@gmail.com';
$TO_EMAIL = 'to@gmail.com';
$subject = "test";
$from = new SendGrid\Email(null, $FROM_EMAIL);
$to = new SendGrid\Email(null, $TO_EMAIL);
$htmlContent = '<!DOCTYPE html><html><head><title></title></head><body><p>hi this is test</p></body></html>';
$content = new SendGrid\Content("text/html",$htmlContent);
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$sg = new \SendGrid($API_KEY);
$response = $sg->client->mail()->send()->post($mail);
if ($response->statusCode() == 202)
{
echo 'done';
}
else
{
echo 'false';
}
答案 0 :(得分:0)
遇到相同的问题,您必须在SendGrid\Email
前面加上反斜杠\
:
$from = new \SendGrid\Email(null, $FROM_EMAIL);
$to = new \SendGrid\Email(null, $TO_EMAIL);
有关更多详细信息,已在sendgrid-php
期中进行了讨论
https://github.com/sendgrid/sendgrid-php/issues/341