WEB API を使用してメールを送信するように sendgrid v3 を構成する方法を知る必要があります。次のコードを使用していますが、エラーが表示されます。
$request_body = json_decode('{
"asm": {
"content": [
{
"type": "text/html",
"value": "'. $body .'"
}
],
"from": {
"email": "'. $sender_email .'",
"name": "'. $sender_name .'"
},
"personalizations": [
{
"bcc": [
{
"email": "'. $receiver_email .'",
"name": "'. $receiver_name .'"
}
],
"headers": {
"X-Accept-Language": "en",
"X-Mailer": "MailerKobsa"
},
"send_at": 1409348513,
"subject": "'. $subject .'",
"substitutions": {
"id": "substitutions",
"type": "object"
},
"to": [
{
"email": "'. $receiver_email .'",
"name": "'. $receiver_name .'"
}
]
}
],
"reply_to": {
"email": "'. $sender_email .'",
"name": "'. $sender_name .'"
},
"send_at": 1409348513,
"subject": "'. $subject .'"
}');
しかし、次のエラーが表示されます。
415array(9) { [0]=> string(36) "HTTP/1.1 415 Unsupported Media Type " [1]=> string(14) "Server: nginx " [2]=> string(36) "Date: Fri, 25 Nov 2016 23:53:37 GMT " [3]=> string(31) "Content-Type: application/json " [4]=> string(19) "Content-Length: 92 " [5]=> string(23) "Connection: keep-alive " [6]=> string(22) "X-Frame-Options: DENY " [7]=> string(1) " " [8]=> string(0) "" } {"errors":[{"message":"Content-Type should be application/json.","field":null,"help":null}]}415array(9) { [0]=> string(36) "HTTP/1.1 415 Unsupported Media Type " [1]=> string(14) "Server: nginx " [2]=> string(36) "Date: Fri, 25 Nov 2016 23:53:38 GMT " [3]=> string(31) "Content-Type: application/json " [4]=> string(19) "Content-Length: 92 " [5]=> string(23) "Connection: keep-alive " [6]=> string(22) "X-Frame-Options: DENY " [7]=> string(1) " " [8]=> string(0) "" } {"errors":[{"message":"Content-Type should be application/json.","field":null,"help":null}]}
Githubにある「シンプル」バージョンを使用してメールを送信しようとしたこと、APIキーを正しく構成したこと、およびシンプルバージョンで問題なくメールを送信できたことを言及する必要があります。しかし、高度なバージョンでは、受信者の電子メールだけでなく、受信者の名前などの情報を追加する必要があります。
私はキャンペーンを使用せず、データベースから情報を抽出しません。CSV ファイルから情報を抽出します。