php - 无法到达 https://api.sendgrid.com/v3/mail/send 端点 (?)
问题描述
我在使用 Sendgrid 使用 PHP 发送电子邮件时遇到问题 - 我尝试发送最简单的电子邮件,我得到 202 状态,但没有发送电子邮件。
我已经联系了 SendGrid 支持团队以确认我的 API KEY 有效并且具有正确的权限。
我用:
- PHP 7.3.0
- Composer 1.8.3
这是我的composer.json:
{
"require": {
"sendgrid/sendgrid": "^7.3",
"sendgrid/php-http-client": "~3.9.6"
}
}
我制作了最简单的测试端点来发送电子邮件。它在这里-> http://konfiguratorszkolen.pl/send-email/test.php
此 PHP 中的代码如下所示:
<?php
require 'vendor/autoload.php';
$email = new \SendGrid\Mail\Mail();
$email->setFrom("testemail1@gmail.com", "Example User");
$email->setSubject("Sending with Twilio SendGrid is Fun");
$email->addTo("testemail2@gmail.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("MyValidAPIKey");
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";
}
?>
Sendgrid 支持团队说我不向https://api.sendgrid.com/v3/mail/send端点发送 POST 请求。但不应该 $response = $sendgrid->send($email); 做那份工作?
可能是什么问题?我怎样才能到达终点?
我想补充一点,这种代码在 5 月运行良好。它在几周前停止了。我究竟做错了什么?
解决方案
推荐阅读
- r - .getReactiveEnvironment()$currentContext() 中的 R studio / R 脚本错误:
- java - 数组*不抛出越界异常
- python - 使用 python 创建 Discord Webhook
- javascript - 如何为窗口对象等特定范围内的函数调用创建默认父对象?
- c++ - C++读取/sys/class/net/eth0/operstate遇到权限被拒绝
- python - 如何解决从列表中打印单词的 IndexError 问题
- r - 将深度嵌套列表转换为数据框
- javascript - ASP.Net (VB) - 使用先前下拉列表中的数据填充下拉列表。[未找到成员]
- javascript - JavaScript 在滚动时更改背景颜色
- spring - 如何使用 gradle 属性禁用 sonarqube 安全热点?