【发布时间】:2017-06-22 02:20:18
【问题描述】:
我有以下代码,我想与本地版本的 SendGrid 一起使用。唯一的问题是它不是我的密码。经过研究,我发现密码与 API Key 完全不同。我无法更新 API 密钥,因为更新时邮件不会在我的实时生产服务器上发送。
我本地的代码如下:
<?php
require '../database/vendor/autoload.php';
// If you are not using Composer
// require("path/to/sendgrid-php/sendgrid-php.php");
$from = new SendGrid\Email(null, "test@test.com");
$subject = "Sending with SendGrid is Fun";
$to = new SendGrid\Email(null, "test@test.com");
$content = new SendGrid\Content("text/plain", "and easy to do anywhere, even with PHP");
$mail = new SendGrid\Mail($from, $subject, $to, $content);
//$apiKey = getenv('xxxxxx');
//$apiKey = "xxxxxx";
$sg = new \SendGrid("xxxxxx");
$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode();
print_r($response->headers());
echo $response->body();
?>
但是我不断收到以下错误:
提供的授权授权无效、过期或被撤销=
【问题讨论】:
-
如果您的服务器现在不发送邮件,为什么不能更新到 API 密钥,然后它才能工作?
-
我是说一旦我更新了 api 密钥,邮件将无法工作。但事实并非如此,因为我发现您可以创建多个 api 密钥。之后,挖掘和搜索,我发现因为我们运行的是 SendGrid 版本 1,所以我们一开始就没有 api 密钥。即使我们这样做了,您也可以创建多个彼此不冲突的 api 密钥。