$emailAddress must be a valid email address

Created on 29 October 2022, about 2 years ago
Updated 16 March 2023, almost 2 years ago

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.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡΄Colombia sergiogsanchez

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States greggles Denver, Colorado, USA

    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 πŸ“Œ Create 8.x-2.1 release Fixed 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!

  • πŸ‡ΊπŸ‡ΈUnited States jfurnas

    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)

  • πŸ‡ΉπŸ‡ΉTrinidad and Tobago xamount

    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

Production build 0.71.5 2024