使用PHP SDK使用SendGrid和PHP发送电子邮件
经过几个小时的研究,我正在寻求帮助 我想使用SendGrid API,使用这里的PHP SDK,用PHP发送我的电子邮件 实际上,我的代码如下:使用PHP SDK使用SendGrid和PHP发送电子邮件,php,sendgrid,Php,Sendgrid,经过几个小时的研究,我正在寻求帮助 我想使用SendGrid API,使用这里的PHP SDK,用PHP发送我的电子邮件 实际上,我的代码如下: export SENDGRID_API_KEY='SG.xxxxxxxxxxxx' 要求(“sendgrid/sendgrid php.php”) 测试页面时,出现以下错误: 401 Array ( [0] => HTTP/1.1 401 Unauthorized [1] => Server: nginx [2] => Date:
export SENDGRID_API_KEY='SG.xxxxxxxxxxxx'
要求(“sendgrid/sendgrid php.php”)
测试页面时,出现以下错误:
401 Array ( [0] => HTTP/1.1 401 Unauthorized [1] => Server: nginx [2] => Date: Tue, 03 Sep 2019 23:44:21 GMT [3] => Content-Type: application/json [4] => Content-Length: 88 [5] => Connection: keep-alive [6] => Access-Control-Allow-Origin: https://sendgrid.api-docs.io [7] => Access-Control-Allow-Methods: POST [8] => Access-Control-Allow-Headers: Authorization, Content-Type, On-behalf-of, x-sg-elas-acl [9] => Access-Control-Max-Age: 600 [10] => X-No-CORS-Reason: https://sendgrid.com/docs/Classroom/Basics/API/cors.html [11] => [12] => ) {"errors":[{"message":"Permission denied, wrong credentials","field":null,"help":null}]}
请问我做错了什么
我查看了文档,但找不到导致错误的原因
非常感谢您的帮助。
.env
需要通过安装vlucas/phpdotenv
编写器需要vlucas/phpdotenv
并且API密钥不带导出
关键字或引号
SENDGRID_API_KEY=SG.xxxxxxxxxxxx
您使用的是纯php还是像Laravel这样的框架?您是否使用composer安装了
vulcas/dotenv
和sendgrid php
软件包?您好,我使用的是纯php。我不安装Vulcan/dotenv或带有Composer的软件包。如果我不使用Composer,文档中是否有类似explain的选项?然后不要使用getenv
函数并硬编码API键
SENDGRID_API_KEY=SG.xxxxxxxxxxxx