php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55122 FILTER_VALIDATE_EMAIL
Submitted: 2011-07-03 17:53 UTC Modified: 2011-07-03 19:08 UTC
From: zachary at stolertech dot com Assigned:
Status: Not a bug Package: Filter related
PHP Version: 5.3.6 OS: Microsoft Windows v6.1.7601
Private report: No CVE-ID: None
 [2011-07-03 17:53 UTC] zachary at stolertech dot com
Description:
------------
The FILTER_VALIDATE_EMAIL filter does not work as it should. If you include an IP address in your email address it filters as not valid.

The email we use for this experiment is php@[123.456.789.0], a fully valid email address. We also tested php@123.456.789.0 and its validates as FALSE.

Test script:
---------------
<?php

$emailwithip = "php@[123.456.789.0]";

if(!filter_var($emailwithip, FILTER_VALIDATE_EMAIL)) {
	echo "EMAIL INVALID"; //Unexpected Result
} else {
	echo "EMAIL VALID"; //Expected Correct Result
}
  
?> 

Expected result:
----------------
TRUE

Actual result:
--------------
FALSE

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-03 18:21 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2011-07-03 18:21 UTC] rasmus@php.net
This is not a valid email address since 123.456.789.0 is an invalid ip. Try 123.123.123.0 as a test ip instead.
 [2011-07-03 18:55 UTC] zachary at stolertech dot com
Thanks, I forgot that IPV4 only goes to 255.

What if you were to use an IPV6 address? It doesn't seem to work.
<?php

$emailwithip = "php@[::1]";

if(!filter_var($emailwithip, FILTER_VALIDATE_EMAIL)) {
	echo "EMAIL INVALID"; //Unexpected Result
} else {
	echo "EMAIL VALID"; //Expected Correct Result
}
  
?>
 [2011-07-03 19:08 UTC] rasmus@php.net
Because again, that is not a valid address. The correct way to specify that address as per the spec is: php@[IPV6:::1]
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 13:01:29 2024 UTC