我有下面的代码,我想在我的本地版本SendGrid中使用它。唯一的问题是它没有排除我的密码。经过研究,我发现密码与API密钥完全不同。我无法更新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();
?>
然而,我一直收到以下错误:
提供的授权授权无效、已过期或revoked=
发布于 2017-06-22 17:10:33
我发现你可以创建多个api密钥。经过挖掘和搜索,我发现因为我们运行的是SendGrid版本1,所以从一开始就没有api密钥。即使我们这样做了,您也可以创建多个彼此不冲突的api密钥。此外,看起来您只有在使用SendGrid的V3之前的版本时才使用用户名和密码
https://stackoverflow.com/questions/44689065
复制