好的,我尝试使用它们提供给我的API一起设置Laravel和SendGrid,但无论如何,我总是收到错误提示
客户端错误:
POST https://api.sendgrid.com/v3/mail/send
导致400 Bad Request
的回复:{“错误”:[{“消息”:“错误 请求”,“字段”:null,“帮助”:null}]}
我尝试使用另一个API密钥,但我一直收到完全相同的错误。
$endpoint = "https://api.sendgrid.com/v3/mail/send";
$client = new \GuzzleHttp\Client();
$headers = [
'Authorization' => 'Bearer MY_API_KEY', //of course, I removed my real API key
'Accept' => 'application/json',
'content-type' => 'application/json'
];
$zData = [
"personalizations"=> [
[
"to"=> [
[
"email"=> "myemail@gmail.com" // I used my private Gmail account
]
],
"subject"=> "Hello, World!"
]
],
"from"=> [
"email"=> "myemail@gmail.com" //here I used my another personal gmail account
],
"content"=> [
[
"type"=> "text/plain",
"value"=> "Hello, World!"
]
]
];
$response = $client->request('POST', $endpoint, [
'headers' => $headers,
$zData
]);