Sendgrid-php: [SOLVED] Substitutions not working

Created on 6 Dec 2018  路  3Comments  路  Source: sendgrid/sendgrid-php

Issue Summary

I have transactional template in send grid. In that email i have placeholders like: [first_name] etc...
I've tryied different options and ways to replace this placeholders.
What should i add to my code in order to make this work?

$from = new From("[email protected]", "Project");
  $tos = [
    new To(
      '[email protected]', 'Example Name', ['first_name' => 'Example name'], 'Hello, test subject!'
    )
  ];
  $email = new Mail($from, $tos);
  $email->setTemplateId('d-********************************');
  $sendgrid = new \SendGrid(_SENDGRID_API_KEY_);
  try {
    $response = $sendgrid->send($email);
  } catch (Exception $e) {
    echo 'Caught exception: ' . $e->getMessage(). "\n";
  }
unknown or a waiting for feedback question

Most helpful comment

Hello @solonifer,

Could you please try this example? Thanks!

With Best Regards,

Elmer

All 3 comments

I have also tried:

$substitutions = [
    "first_name" => "Steve"
];
$email->addDynamicTemplateDatas($substitutions);

Doesn't work for me.

Hello @solonifer,

Could you please try this example? Thanks!

With Best Regards,

Elmer

@thinkingserious thank you!!! Worked for me 馃憤
{{placeholder}} - this was the right placeholder.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

elshafey picture elshafey  路  4Comments

mwsasser picture mwsasser  路  3Comments

morazain picture morazain  路  3Comments

izhukovich picture izhukovich  路  4Comments

bjornmann picture bjornmann  路  3Comments