sendgrid / sendgrid-php

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

addDynamicTemplateData with nested array causes error #1063

Closed Petah closed 2 years ago

Petah commented 2 years ago

Issue Summary

Adding nest dynamic data to a personalisation doesn't work.

Steps to Reproduce

$personalization->addDynamicTemplateData([
    'user' => [
        'name' => 'test',
    ],
]);

Throws error:

E_NOTICE Array to string conversion

28 | /vendor/sendgrid/sendgrid/lib/helper/Assert.php | sprintf
54 | /vendor/sendgrid/sendgrid/lib/mail/Substitution.php | SendGrid\Helper\Assert::string
38 | /vendor/sendgrid/sendgrid/lib/mail/Substitution.php | SendGrid\Mail\Substitution::setKey
210 | /vendor/sendgrid/sendgrid/lib/mail/Personalization.php | SendGrid\Mail\Substitution::__construct
184 | /vendor/sendgrid/sendgrid/lib/mail/Personalization.php | SendGrid\Mail\Personalization::addSubstitution
163 | /classes/Helper/EmailComposer.php | SendGrid\Mail\Personalization::addDynamicTemplateData

Technical details:

Petah commented 2 years ago

NM, I figured it out:

$personalization->addDynamicTemplateData('user', [
    'foo' => [
        'bar' => 'test',
    ],
]);