Problem/Motivation

There is an error when you have a contact form with multiple recipients, and someone submits the contact form:

SendGrid\Exception\TypeException: "$emailAddress" must be a valid email address. Got: aaaaaaa@aaaaa.com in SendGrid\Helper\Assert::email() (line 68 of /app/vendor/fastglass/sendgrid/src/Helper/Assert.php).

Steps to reproduce

  1. Enable the Contact (Core) module
  2. Enable the Sendgrid Integration module and set an API Secret Key
  3. Go to /admin/config/system/mailsystem and set Sendgrid Integration as formatter and sender
  4. Go to /admin/admin/structure/contact edit or create a new contact form with at least two recipients
  5. Go to the contact form view tab and submit the form; you should get the error for the second email recipient address

Proposed resolution

Once we get multiple recipient addresses separated by commas, we need to remove unnecessary spaces at the start of those emails; some modules could create the Mailto string using space after the comma character.

Comments

sergiogsanchez created an issue. See original summary.

sergiogsanchez’s picture

sergiogsanchez’s picture

sergiogsanchez’s picture

Status: Active » Needs review
gaurav-mathur’s picture

gaurav-mathur’s picture

Assigned: gaurav-mathur » Unassigned
StatusFileSize
new146.04 KB
new78.94 KB
new64.97 KB

I reproduce this and apply patch#2 and it's working. adding screenshot for the reference.

perignon’s picture

Status: Needs review » Fixed

Committed! Thanks for the patch and the testing.

Status: Fixed » Closed (fixed)

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

greggles’s picture

Thanks for the work identifying and fixing this bug!

A site that I work on is affected by this and I knew we had upgraded to 8.x-2.0 recently so I was curious why we didn't have this fix. Then I realized that this fix is not in the stable release. I created #3342802: Create 8.x-2.1 release to consider when and whether it's time for an 8.x-2.1 release. If there are other issues worth fixing before making a release please add them there and I can try to help get them fixed.

We've got a workaround for now and will probably roll out the dev version soon, but hoping to use stables where possible.

Thanks!

jfurnas’s picture

I am running PHP 8.1 and using the latest version of sendgrid_integration (with the above patch included in it), and I am receiving the same error message, except it's not returning the 'to' address. I can replicate it across all emails being sent in the system (both custom emails and system emails)

xamount’s picture

Priority: Normal » Major

As said in #11, I am also still experiencing this error message. I have confirmed this twice.

In my case, I am using Sendgrid to send Drupal Commerce emails for order confirmations. Apart from sending the emails to the person (1 recipient), I am using Blind Carbon Copy so now it's 2 recipients and it's breaking Sendgrid.

When I turn off the Blind Carbon Copy, it works (sending to 1 recipient).

So it seems there is something still wrong with sending to multiple email addresses.

This issue is highly critical for me as it's blocking Drupal Commerce orders from going through. I have to turn off Blind Carbon Copy in the meantime. Hence I am raising the priority to "Major" as I have a temporary workaround and hope that the maintainer will re-open this issue.

My exact error message is:

SendGrid\Exception\TypeException: "$emailAddress" must be a valid email address. Got: xxx@xxx.com in SendGrid\Helper\Assert::email() (line 68 of /code/vendor/fastglass/sendgrid/src/Helper/Assert.php).

xxx@xxx.com is the 2nd recipient (the email that I have for bcc).

Drupal 9.54
PHP 8.0.27
SendGrid Integration 8.x-2.1