【问题标题】:Sendgrid: Permission denied, wrong credentialsSendgrid:权限被拒绝,凭据错误
【发布时间】:2017-10-30 02:18:32
【问题描述】:

我正在使用 sendgrid PHP 发送电子邮件。这是我的代码:

require("sendgrid-php.php");

$from = new SendGrid\Email("Example User", "test@example.com");
$subject = "Sending with SendGrid is Fun";
$to = new SendGrid\Email("Example User", "to@gmail.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('SG.key......');
$sg = new \SendGrid($apiKey);

$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode();
echo '<pre>';
print_r($response->headers());
echo '</pre>';
echo $response->body();

当我运行上面的代码时,它向我显示以下错误消息:

401 数组 ( [0] => HTTP/1.1 401 未经授权 [1] => 服务器:nginx [2] => 日期:2017 年 5 月 29 日星期一 17:52:44 GMT [3] => 内容类型:应用程序/json [4] => 内容长度:88 [5] => 连接:保持活动状态 [6] => X 帧选项:拒绝 [7] => 访问控制允许来源:https://sendgrid.api-docs.io [8] => 访问控制允许方法:POST [9] => Access-Control-Allow-Headers:授权,内容类型,代表,x-sg-elas-acl [10] => 访问控制最大年龄:600 [11] => X-No-CORS-原因:https://sendgrid.com/docs/Classroom/Basics/API/cors.html [12] => [13] => ) {"errors":[{"message":"Permission denied, wrong credentials","field":null,"help":null}]}

我不明白为什么会出现与权限相关的错误,因为我刚刚创建了 API 密钥。

【问题讨论】:

标签: php sendgrid


【解决方案1】:

这很常见。理解和做几乎不需要一个小时。您需要设置环境或使用用户名密码认证系统。请阅读official document on Githubdocumentation heredocumentation here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 2016-09-25
    • 2015-09-16
    • 2012-02-11
    • 2016-11-14
    • 2016-12-28
    • 2016-10-18
    相关资源
    最近更新 更多