A customer of mine complains that with filter_var()
and the option FILTER_VALIDATE_EMAIL
an e-mail address like:
john.doe@example.c
gets accepted. So my question now is: How long has a TLD to be at least? I mean we know .com
, .org
, .us
. But TLDs like .g
or .a
don't exist as far as I know.
The further questions are:
I would do something else: Check if the domain can been resolved and if it has an MX record. If not the domain cannot recieve emails and you can reject that email address.
Check also the getmxrr()
function and don't forget the umlautdomains also known as idn or punycode domains use for that the idn_to_ascii()
. Here is a simple example script:
$parts = explode('@', $email);
if(!getmxrr(idn_to_ascii($parts[1]))) {
echo 'Reject email address';
}