你可以使用SendGrid的PHP v5.5.1 API和用户名和密码而不是API Key

时间:2017-06-22 02:20:18

标签: php api sendgrid

我有以下代码,我想用我的本地版本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();
?>

但是我一直收到以下错误:
提供的授权许可无效,已过期或已撤销=

1 个答案:

答案 0 :(得分:0)

我发现你可以创建多个api密钥。之后,挖掘和搜索,我发现因为我们运行的是SendGrid的第1版,所以我们从来没有开始使用api密钥。即使我们这样做,您也可以创建多个不会相互冲突的api密钥。此外,如果使用V3之前版本的SendGrid

,您似乎只使用用户名和密码
相关问题