我正试图在codeigniter中使用sendgrid发送电子邮件。以下是发送电子邮件时执行的代码。但是email模板中的动态值(#name#)不会被"sub"参数中提供的值所替换。只有主体内容被替换。接收邮件没有问题。但是替代值不会被替换。有人能帮忙吗?
$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);
替换必须在个性化设置内,并且需要写入" Substitutions ",然后工作