2
votes

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": "[email protected]"}]}],
  "from": {"email": "[email protected]"},
  "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);
1

1 Answers

0
votes

Substitutions have to be inside the personalizations, and need to be write "substitutions", then works.