无法通过SendGrid v3 API发送自定义HTML模板

时间:2019-08-01 05:26:19

标签: html json sendgrid-api-v3

尝试通过json通过curl通过json将自定义构建的html模板发送到SendGrid v3 api。 '.$emailHtml.'保留我的html,它可以包含图像html标记引用特殊字符。客户构建自己的html模板。

无法弄清楚如何用我的html设置正确的json参数列表。

$url = "https://api.sendgrid.com/v3/mail/send";
$session = curl_init($url);

// Tell PHP not to use SSLv3 (instead opting for TLS)
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);

curl_setopt($session, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $SENDGRID_API_KEY,'Content-Type: application/json'));

curl_setopt ($session, CURLOPT_POST, true);

curl_setopt($session, CURLOPT_POSTFIELDS, '{"personalizations": [{"to": [{"email": "receive@example.com"}]}],"from": {"email": "test@example.com"},"subject": "Sending with SendGrid is Fun","content": [{"type": "text/html", "value": "'.$emailHtml.'"}]}');

curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($session);
curl_close($session);

0 个答案:

没有答案