sendgrid / sendgrid-php

The Official Twilio SendGrid PHP API Library
https://sendgrid.com
MIT License
1.49k stars 623 forks source link

Unable to attach variables into a dynamic template #1026

Closed andoitz closed 3 years ago

andoitz commented 3 years ago

Issue Summary

I cant attach variables into my dynamic template.

Steps to Reproduce

  1. I use variables like {my_variable}
  2. I follow this documentation: https://github.com/sendgrid/sendgrid-php/blob/main/USE_CASES.md#transactional-templates
  3. I receive the email with no variables replaced at all.
  4. I attach the code bellow, as you can see I have tried many different ways already.

Code Snippet

        $email = new \SendGrid\Mail\Mail();
        $email->setFrom("my email");
        $email->addTo(
            $request->email,
            "username",
            [
                'my_variable' => '12',
                '{{my_variable}}' => '13',
                '{{ my_variable}}' => '13'
            ],
            0
        );
        $email->setTemplateId( new \SendGrid\Mail\TemplateId( "my template id" ) );
        $email->addDynamicTemplateDatas(array("my_variable" => "12", "{{my_variable}}" => "13"));
        $email->addCustomArgs(array("my_variable" => "12", "{{my_variable}}" => "13"));

        $email->addHeader("x-smtpapi", json_encode(array("my_variable" => "10")));

        $sendgrid = new \SendGrid( env("SENDGRID_API_KEY") );
        $response = $sendgrid->send($email);

Exception/Log

No errors

paste exception/log here

No errors

Technical details: