我正在尝试使用Sendgrid发送我的第一封电子邮件:
$sendgrid = new SendGrid('username', 'xx.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxx'); $email = new SendGrid\Email(); $email->addTo("email1@gmail.com") ->setFrom("email@domain.com") ->setSubject("Sending with SendGrid is Fun") ->setHtml("and easy to do anywhere, even with PHP");
这是我遇到的错误:
PHP致命错误:未捕获的异常'SendGrid\Exception',消息为"{"errors":["Bad username/password"],"message":"error"}'
我使用来自Sendgrid设置的真实API密钥信息,而不是'username'和'xx.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxx'.
我使用了创建API密钥后提供的长字符串密钥.但是这行似乎还有问题:$ sendgrid = new SendGrid('username','xx.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxx');
我应该在哪里获取授权信息,以便我不会收到错误的用户名/密码错误?
另一个可能的答案是只将api键传递给SendGrid()构造函数;
$sendgrid = new SendGrid('xx.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxx'); $email = new SendGrid\Email(); $email->addTo("email1@gmail.com") ->setFrom("email@domain.com") ->setSubject("Sending with SendGrid is Fun") ->setHtml("and easy to do anywhere, even with PHP");