我在這里遵循示例: https: //github.com/sendgrid/sendgrid-php/blob/master/examples/mail/mail.php我已經(jīng)刪除了大部分參數(shù)來(lái)發(fā)送一封非?;镜碾娮余]件:<?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": "alice@domain.com", "name": "Sender Alice" }, "personalizations": [ { "to": [ { "email": "bob@domain.com", "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";}?>執(zhí)行時(shí)出現(xiàn)以下錯(cuò)誤{"errors":[{"message":"Content-Type should be application/json.","field":null,"help":null}]}看看原來(lái)的例子,我沒有看到任何我可能刪除的東西會(huì)導(dǎo)致這種情況,盡管我可能是錯(cuò)的。感謝您的任何意見。
由于 JSON 錯(cuò)誤,使用 sendgrid 通過(guò) PHP 發(fā)送郵件失敗
阿波羅的戰(zhàn)車
2023-08-19 16:22:31