php - 如何使用 Sendgrid 发送电子邮件?
问题描述
如何使用 Sendgrid 发送邮件,我尝试了很多次但给出错误,错误如找不到类,我也安装了 composer 但我无法理解,请给我解决方案 错误图像:
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';
}
解决方案
有同样的问题,你必须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
推荐阅读
- memory-management - CVODE PETSc 接口给出内存损坏错误
- matplotlib - 如何从日志文件中绘制损失
- python - Django - 如何删除数据库中的对象?
- maven - 运行 mvn compile 时出现 401 Unauthorized
- reactjs - 未找到规则“简单导入排序/排序”的定义 simple-import-sort/sort
- c# - 使用类/构造函数保存数据时无法在 C# 应用程序中保存到列表/字典
- java - 数组类型的组件类型什么时候也是数组类型?
- laravel - Laravel:在 where 子句中使用“LIKE”
- flutter - 使用 Custom Painter 在 Flutter 中掩盖路径和绘画
- flutter - 滚动控制器出错