Problem/Motivation
"The website encountered an unexpected error. Please try again later." happened when SendGrid Integration try to send email through "\Drupal::service('plugin.manager.mail') ->mail($module, $key, $to, $langcode, $params, $from, $send)".
And "$to" contains multiple recipients.
logs below:
"SendGrid\Exception\TypeException: "$name" must be a string. Got: (C:\xampp\htdocs\drupal9test\vendor\fastglass\sendgrid\src\Helper\Assert.php Line 41 SendGrid\Helper\Assert::string())"
Steps to reproduce
execute this code with appropriate variables as follows:
$to = 'test1@example.com,test2@example.com.test3@example.com'
$response = \Drupal::service('plugin.manager.mail') ->mail($module, $key, $to, $langcode, $params, $from, $send);
Proposed resolution
- Fix the code below
"\modules\sendgrid_integration\src\Plugin\Mail\SendGridMail.php"
Line 246 :
"$personalization0->addTo(new To($sendtoarrayparsed[0], isset($sendtoarrayparsed[1])) ? $sendtoarrayparsed[1] : NULL);"
Fix to :
"$personalization0->addTo(new To($sendtoarrayparsed[0], isset($sendtoarrayparsed[1]) ? $sendtoarrayparsed[1] : NULL));"
The root cause is typo about Ternary operator.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | sendgrid_integration-3210891.patch | 689 bytes | lzagata |
Comments
Comment #2
tsuyopin commentedComment #3
perignon commentedTest the latest version of code and not Alpha4. There are issues in Alpha4.
Comment #4
lzagata commentedThis error is still present in 8.x-2.0-alpha5, so I added a patch that fixes Ternary operator issue.
Comment #5
radelson commentedThe patch from https://www.drupal.org/project/sendgrid_integration/issues/3210891#comme... indeed fix this problem.
Without the patch, isset() is passing a boolean and it fails here :
I changed the title as I missed it at first when looking through the issue queue for this problem.
Bumped it to major as well as the end user is presented with a WSOD and it's not an edge case.
I mark this as RTBC, the patch is simply fixing a typo.
Comment #6
perignon commentedThis patch is for some reason corrupt, the file paths are wrong.
Comment #8
perignon commentedCorrected the paths in the patch and it applied cleanly. Pushed!