sendgrid-php icon indicating copy to clipboard operation
sendgrid-php copied to clipboard

Email Validation is not RFC5321 compliant

Open jayesbe opened this issue 5 years ago • 7 comments

Issue Summary

Email addresses where the local part end in a period are being flagged as invalid even though they are RFC5321 compliant.

This comment from seven years ago defines the issue fairly well

https://www.php.net/manual/pt_BR/function.filter-var.php#112492

Copying here to make it easier.

I found some addresses that FILTER_VALIDATE_EMAIL rejects, but RFC5321 permits:

<?php
foreach (array(
        '[email protected]',
        '(comment)[email protected]',
        '"this is v@lid!"@example.com',
        '"much.more unusual"@example.com',
        'postbox@com',
        'admin@mailserver1',
        '"()<>[]:,;@\\"\\\\!#$%&\'*+-/=?^_`{}| ~.a"@example.org',
        '" "@example.org',
    ) as $address) {
    echo "<p>$address is <b>".(filter_var($address, FILTER_VALIDATE_EMAIL) ? '' : 'not')." valid</b></p>";
}
?>

Results:

  • [email protected] is not valid
  • (comment)[email protected] is not valid
  • "this is v@lid!"@example.com is not valid
  • "much.more unusual"@example.com is not valid
  • postbox@com is not valid
  • admin@mailserver1 is not valid
  • "()<>[]:,;@"\!#$%&'*+-/=?^_`{}| ~.a"@example.org is not valid
  • " "@example.org is not valid

The documentation does not saying that FILTER_VALIDATE_EMAIL should pass the RFC5321, however you can meet with these examples (especially with the first one). So this is a note, not a bug report.

Technical details:

sendgrid/php-http-client 3.10.7 sendgrid/sendgrid 7.6.0 using PHP.

So the issue is we have users in our system that do have email addresses where the localpart ends in a period. This email address is being flagged as invalid even though it should be perfectly find to send an email to.

I guess the question is, does sendgrid support the above email addresses that are valid according RFC5321 ?

jayesbe avatar Jun 25 '20 11:06 jayesbe

Hello @jayesbe,

With respect to the behavior of FILTER_VALIDATE_EMAIL, assuming we support sending emails in one or more of the results you provided, would you propose the implementation of an alternative filter (likely within setEmailAddress) that better conforms to RFC521? If so, I will re-title and add this issue to our internal backlog to be prioritized.

For "does sendgrid support the above email addresses that are valid according RFC5321?", I would suggest reaching out to our support team.

With best regards,

Elmer

thinkingserious avatar Jun 26 '20 03:06 thinkingserious

@thinkingserious this is the best I can do in my research.. from the author of the filter_var regex implementation himself.

https://stackoverflow.com/a/28770784

https://stackoverflow.com/questions/28280176/php-filter-var-and-rfc-5322

jayesbe avatar Jun 26 '20 10:06 jayesbe

@jayesbe,

Thanks for the research and links!

For a short term fix, have you tried bypassing the email validation filter for the emails that are failing?

Syncing our internal validation at the API level with the appropriate filtering seems to be the long term fix.

thinkingserious avatar Jun 26 '20 20:06 thinkingserious

Just checking in to find out if you have implemented the short term fix and your thoughts on the long term fix. Thanks!

thinkingserious avatar Jul 06 '20 23:07 thinkingserious

I'm adding this feature request to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

eshanholtz avatar Aug 07 '20 18:08 eshanholtz

I just hit the same issue with a user trying to sign up for our service with an email like test.o’[email protected]

esetnik avatar Nov 01 '20 18:11 esetnik

I have same issue with an [email protected]

WebMago avatar Oct 26 '21 17:10 WebMago