![](/img/trans.png)
[英]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.