Closed jshampur closed 3 years ago
Mixing a numeric/string variables in specific order in the personalization variable array results in an exception:
$from = New From($fromEmail, $fromName); $tos = [ New To($email, $name, $templateValues) ]; $emailObj = new Mail($from, $tos); // **This triggers the exception - see below** ....
if the $templateValues array is set like this:
$templateValues = [ "first_name" => "jay", "last_name" => "smith", "amount" => 20, "album" => "dark side of the moon" ]
The exception is triggered.
if I change the order to $templateValues = [ "first_name" => "jay", "last_name" => "smith", "album" => "dark side of the moon" , "amount" => 20, ]
it works. Just to be safe, I actually made "amount" =>"20" which works regardless of where it appears in the list.
The exception was not caught as I was following examples from the Sendgrid docs and did not wrap the code in try...catch block.
Uncaught SendGrid\Mail\TypeException: $value must be of type string, array or object. in /var/www/html/api /sendgrid-php/lib/mail/Substitution.php:88
Took me a while to figure this out.
Hi @jshampur,
v7.3.0 is pretty outdated. The latest version is 7.9.1. I recommend you try with the latest version and see if you still face the same issue.
v7.3.0
7.9.1
Thanks - I'll give it a go.
Issue Summary
Mixing a numeric/string variables in specific order in the personalization variable array results in an exception:
Code Snippet
if the $templateValues array is set like this:
$templateValues = [ "first_name" => "jay", "last_name" => "smith", "amount" => 20, "album" => "dark side of the moon" ]
The exception is triggered.
if I change the order to $templateValues = [ "first_name" => "jay", "last_name" => "smith", "album" => "dark side of the moon" , "amount" => 20, ]
it works. Just to be safe, I actually made "amount" =>"20" which works regardless of where it appears in the list.
The exception was not caught as I was following examples from the Sendgrid docs and did not wrap the code in try...catch block.
Exception/Log
Technical details:
Took me a while to figure this out.