简体   繁体   中英

Substitution tags in sendgrid not working

I am trying to send email using sendgrid in codeigniter. Following is the code executed while sending the email. But the dynamic values in the email template (#name#) is not replaced using the value provided in "sub" parameter. Only the body content get replaced.There is no problem for receiving email. But substitution values are not replaced. Anyone can help?

$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);

替代必须在个性化设置之内,并且需要写上“替代”,然后才能起作用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM