Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP SDK使用SendGrid和PHP发送电子邮件_Php_Sendgrid - Fatal编程技术网

使用PHP SDK使用SendGrid和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:

经过几个小时的研究,我正在寻求帮助

我想使用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: 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