9

Sample valid e-mail address:

"this is a valid address"@example.com

PHP code:

<?php
header('Content-Type: text/plain');

$email = '"this is a valid address"@example.com';
$checked = filter_var($email, FILTER_VALIDATE_EMAIL);
var_dump($email, $checked);

Output on one server: (PHP Version 5.2.6):

string(37) ""this is a valid address"@example.com"
string(37) ""this is a valid address"@example.com"

phpinfo():

Input Validation and Filtering      enabled
Revision                            $Revision: 1.52.2.42 $

Directive             Local Value   Master Value
filter.default        unsafe_raw    unsafe_raw
filter.default_flags  no value      no value

Output on another server (PHP Version 5.3.3):

string(37) ""this is a valid address"@example.com"
bool(false)

phpinfo():

Input Validation and Filtering      enabled
Revision                            $Revision: 298196 $

Directive             Local Value   Master Value
filter.default        unsafe_raw    unsafe_raw
filter.default_flags  no value      no value

I cannot see anything in the documentation to suggest that this has changed, so perhaps it's some other configuration setting.

TRiG
  • 10,148
  • 7
  • 57
  • 107
  • [Tests for PHP mail validation](http://fightingforalostcause.net/misc/2006/compare-email-regex.php), [Semi related answer](http://stackoverflow.com/questions/12026842/how-to-validate-an-email-address-in-php/12026863#12026863), [Commits](https://github.com/php/php-src/commits/master/ext/filter/logical_filters.c) and [Changelog](http://nl.php.net/ChangeLog-5.php). Conclusion: no not consistent ;-) it has been improved a couple of times. – PeeHaa Nov 21 '12 at 13:17
  • 1
    **That might be a valid email address but anyone using it is not really valid... in the ``.** *If you CAN do some things, it does not really mean you SHOULD.* I'd absolutely NEVER send an email to an address like that, out of respect for sanity. – CodeAngry Aug 30 '13 at 00:04

1 Answers1

6

As you can see on http://3v4l.org/vKONS the usage of the filter FILTER_VALIDATE_EMAIL it is not consistent!

http://3v4l.org/vKONS outputs for PHP 5.2.0, 5.2.14 - 5.2.17, 5.3.3 - 5.3.18, 5.4.0 - 5.4.8

string(37) ""this is a valid address"@example.com" 
bool(false)

and for 5.2.1 - 5.2.13, 5.3.0 - 5.3.2

string(37) ""this is a valid address"@example.com" 
string(37) ""this is a valid address"@example.com"

It is remarkable that it worked for 5.2.0 but not 5.2.1-5.2.13 and then again for 5.2.14!!!

Btw 3v4l.org is a great resource to check such behavior changes across all available PHP versions.

There are several bugs open including the term FILTER_VALIDATE_EMAIL, but none seems to match your kind of error. You might add it to the PHP bugtracker...

powtac
  • 40,542
  • 28
  • 115
  • 170