[英]How to add substitution tags to the subject of the email in SendGrid using the xsmtp-api with the php library
[英]Substitution tags in sendgrid not working
我正在尝试在codeigniter中使用sendgrid发送电子邮件。 以下是发送电子邮件时执行的代码。 但是,不会使用“ sub”参数中提供的值替换电子邮件模板(#name#)中的动态值。 仅替换正文内容。接收电子邮件没有问题。 但是替换值不会被替换。 有人可以帮忙吗?
$pass = 'api key here';
$url = 'https://api.sendgrid.com/';
$params = '{
"personalizations": [{"to": [{"email": "galtech.staffs@gmail.com"}]}],
"from": {"email": "galtech16@gmail.com"},
"subject":"Hello, World!","content": [{"type": "text/plain","value": "Here is the body content!"}],
"sub": {
"#name#": "sssss"
},
"template_id" : "9ceb8d95-8586-4240-a6fc-f36374bce3ca"
}';
$request = $url.'v3/mail/send';
$headr = array();
$headr[0] = 'Authorization: Bearer '.$pass;
$headr[1] = 'Content-Type: application/json';
$session = curl_init($request);
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_HTTPHEADER,$headr);
$response = curl_exec($session);
var_dump($response);
curl_close($session);
替代必须在个性化设置之内,并且需要写上“替代”,然后才能起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.