我需要知道如何配置 sendgrid v3 以使用 WEB API 发送电子邮件。我正在使用以下代码,但它显示了一个错误:
$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 中的“简单”版本发送电子邮件,我已经正确配置了我的 apikey,并且我已经能够在简单版本中发送电子邮件而没有任何问题。但在高级版本中,我需要添加更多信息,例如收件人姓名,而不仅仅是他的电子邮件。
我不使用广告系列,不从数据库中提取信息。我从 CSV 文件中提取信息。