我在這里遵循示例: https: //github.com/sendgrid/sendgrid-php/blob/master/examples/mail/mail.php我已經刪除了大部分參數來發送一封非?;镜碾娮余]件:<?phprequire 'vendor/autoload.php'; // If you're using Composer (recommended)$apiKey = getenv('SENDGRID_API_KEY');$sg = new \SendGrid($apiKey);$request_body = json_decode('{ "content": [ { "type": "text/html", "value": "<html><p>Hello, world!</p></html>" } ], "from": { "email": "[email protected]", "name": "Sender Alice" }, "personalizations": [ { "to": [ { "email": "[email protected]", "name": "Receiver Bob" } ] } ], }');try { $response = $sg->client->mail()->send()->post($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n";} catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n";}?>執行時出現以下錯誤{"errors":[{"message":"Content-Type should be application/json.","field":null,"help":null}]}看看原來的例子,我沒有看到任何我可能刪除的東西會導致這種情況,盡管我可能是錯的。感謝您的任何意見。
1 回答

茅侃侃
TA貢獻1842條經驗 獲得超21個贊
,嘗試刪除request_body 變量中的最后一個。
改變
"personalizations": [
{
"to": [
{
"email": "[email protected]",
"name": "Receiver Bob"
}
]
}],
對此
"personalizations": [
{
"to": [
{
"email": "[email protected]",
"name": "Receiver Bob"
}
]
}]
當我遇到這些問題時,我會針對驗證器運行 json。很多時候它會讓我知道從哪里開始。
https://jsonlint.com/
- 1 回答
- 0 關注
- 131 瀏覽
添加回答
舉報
0/150
提交
取消