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

CommentFileSizeAuthor
#4 sendgrid_integration-3210891.patch689 byteslzagata

Comments

tsuyopin created an issue. See original summary.

tsuyopin’s picture

Issue summary: View changes
perignon’s picture

Status: Active » Postponed (maintainer needs more info)

Test the latest version of code and not Alpha4. There are issues in Alpha4.

lzagata’s picture

StatusFileSize
new689 bytes

This error is still present in 8.x-2.0-alpha5, so I added a patch that fixes Ternary operator issue.

radelson’s picture

Title: The website encountered an unexpected error. Please try again later. » WSOD trying to send mail to multiple addresses : SendGrid\Exception\TypeException: "$name" must be a string. Got:
Version: 8.x-2.0-alpha4 » 8.x-2.x-dev
Priority: Normal » Major
Status: Postponed (maintainer needs more info) » Reviewed & tested by the community

The 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 :

  /**
   * Add a name to a EmailAddress object
   *
   * @param string $name The name of the person associated with the email
   *
   * @throws SendgridException
   */
  public function setName($name) {
    Assert::string($name, 'name');

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.

perignon’s picture

This patch is for some reason corrupt, the file paths are wrong.

  • Perignon committed 1ffd025 on 8.x-2.x authored by lzagata
    Issue #3210891 by lzagata, Perignon: WSOD trying to send mail to...
perignon’s picture

Status: Reviewed & tested by the community » Fixed

Corrected the paths in the patch and it applied cleanly. Pushed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.