首页 > 解决方案 > 无法到达 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 月运行良好。它在几周前停止了。我究竟做错了什么?

标签: phpsendgrid

解决方案


推荐阅读