Filter var for validating email is not validating emails correctly
| Request #49576 | Filter var for validating email is not validating emails correctly | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2009-09-17 08:53 UTC | Modified: | 2012-08-16 18:01 UTC |
|
||||||||||
| From: | mparkin at de-facto dot com | Assigned: | rasmus (profile) | |||||||||||
| Status: | Wont fix | Package: | *General Issues | |||||||||||
| PHP Version: | 5.* | OS: | * | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2010-04-02 07:40 UTC] rasmus@php.net
-Status: Open +Status: Assigned -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: rasmus
[2010-04-02 07:40 UTC] rasmus@php.net
[2010-04-02 19:57 UTC] rasmus@php.net
-Status: Assigned +Status: Closed
[2010-04-02 19:57 UTC] rasmus@php.net
[2010-08-05 16:41 UTC] alexsander dot rosa at gmail dot com
[2010-08-14 20:48 UTC] kalle@php.net
-Status: Closed +Status: Re-Opened
[2010-08-14 20:48 UTC] kalle@php.net
[2010-08-14 21:10 UTC] grangeway at hotmail dot com
Additionally: 1) at the moment, I believe the current regex does not allow fred@com as an email address. Albeit, it's going back almost 10 years now - I'm pretty sure I received an email from someone @tld, complaining that a regex did not allow their valid email address to sign up. 2) The issue the user hit is the phpmailer class contains the following code to validate email addresses against FILTER_VALIDATE_EMAIL regardless of whether SMTP or mail() is the sending method. 550 public static function ValidateAddress($address) { 551 if (function_exists('filter_var')) { //Introduced in PHP 5.2 ... else regex[2010-08-15 02:09 UTC] pajoye@php.net
-Status: Re-Opened +Status: Feedback -PHP Version: 5.*, 6 +PHP Version: 5.*
[2010-08-15 02:09 UTC] pajoye@php.net
[2010-08-17 21:34 UTC] michael at squiloople dot com
You might find this useful, taken directly from my article on E-mail address validation, in deciding whether or not to allow single-label domain names: "There is some confusion over whether or not single-label domain names are allowed — michael@squiloople, for example. People often cite the following section in RFC 5321 to argue that they are not allowed: "'Only resolvable, fully-qualified domain names (FQDNs) are permitted when domain names are used in SMTP. In other words, names that can be resolved to MX RRs or address (i.e., A or AAAA) RRs (as discussed in Section 5) are permitted, as are CNAME RRs whose targets can be resolved, in turn, to MX or address RRs. Local nicknames or unqualified names MUST NOT be used.' "The implicit premise here is that TLD-only domain names cannot be resolved to MX RRs. This is simply untrue: both checkdnsrr('ai', 'MX') and getmxrr('ai', $array) return true, showing that single-label domain names can, and do, resolve to MX RRs. Additionally, http://www.to/ is a valid, and active, domain. Therefore, michael@squiloople is valid (although in this example, ‘squiloople’ is not a TLD). "And as an extra note, here’s another excerpt from RFC 5321: "'In the case of a top-level domain used by itself in an email address, a single string is used without any dots.'"[2012-08-16 16:48 UTC] damien dot regad at merckgroup dot com
Going back to what grangeway posted 2 years ago, the filter still does not accept single-domain addresses: php > var_export( filter_var( 'user@localhost', FILTER_VALIDATE_EMAIL ) ); false I tested with PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli) on Ubuntu 12.04 However, if I understand well the ABNF[1] in the RFC specification [2], this should in fact be allowed (see sections 3.4.1 and 3.2.3 for details): addr-spec = local-part "@" domain domain = dot-atom / domain-literal / obs-domain dot-atom = [CFWS] dot-atom-text [CFWS] dot-atom-text = 1*atext *("." 1*atext) The last bit (dot-atom-text) says that there must be 1 or more chars followed by zero or more groups of ("." followed by 1 or more chars). It would be nice to have this fixed. Thanks in advance ! [1] http://en.wikipedia.org/wiki/Augmented_Backus%E2%80%93Naur_Form [2] http://tools.ietf.org/html/rfc5322[2012-08-16 18:01 UTC] rasmus@php.net
-Status: Feedback +Status: Wont fix
[2012-08-16 18:01 UTC] rasmus@php.net
[2012-08-16 19:03 UTC] levim@php.net
[2012-08-17 07:09 UTC] damien dot regad at merckgroup dot com
[2015-04-07 10:28 UTC] al at cubecart dot com
Code: var_dump(filter_var('john.doé@example.com', FILTER_VALIDATE_EMAIL)); Expected output: john.doé@example.com Actual output: false This occurs with all PHP versions <= 5.6