1

I know this e-mail address works, because I send mail to myself on it. So why does this code not do what I think it should:

$email = 'enquiry_b337575afd6632d06ea58b9b088f35ee6c5682ba5ec768bf3b80c07db2da257d@uat.abc.com';
if (filter_var($email, FILTER_VALIDATE_EMAIL))
{
  print 'is valid';
}
else
{
  print 'is not valid';
}

It prints "is not valid". But I'm pretty sure that e-mail address is correct. Is it perhaps too long and they check for some specific length? Because the last time I checked an e-mail address can be up to 255 characters in length.

Anyone know why this is happening?

UPDATE 1

If I shorted it to this:

$email = 'enquiry_b337575afd6632d06ea58b9b088f35ee6c5682ba5ec768bf3b80c07d@uat.abc.com';

Then it works. So there must be some kind of max length kicking in...

rockstardev
  • 13,479
  • 39
  • 164
  • 296
  • Because email addresses are virtually impossible to reliably verify, aside from actually sending an email and having the user click a link in it or otherwise confirm their reciept. – Sammitch Sep 29 '17 at 17:34
  • 1
    The [validator isn't wrong](https://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address) as that address is wildly outside of the allowed length limits: "...the Mailbox must be no more than 254 characters to keep the path under 256.". – tadman Sep 29 '17 at 17:35
  • 2
    I found the answer here: https://stackoverflow.com/questions/21631366/php-filter-validate-email-max-length ... the "local" part of an e-mail address may only be 64 characters. – rockstardev Sep 29 '17 at 17:36
  • @tadman, that address is nowhere near 256. The issue is the "local" part... part before the @. That may only be 64 chars in length. – rockstardev Sep 29 '17 at 17:38
  • The local part is a factor too. Your original looked a lot longer due to the scroll-bar element. – tadman Sep 29 '17 at 17:39
  • 1
    You should answer your own question and accept it. – Spartacus Sep 29 '17 at 18:04

1 Answers1

0

I found the answer here: PHP FILTER_VALIDATE_EMAIL max length

The problem is that the local part (the part before the @) may only be 64 characters in length. Despite it working on Centos. The PHP Validate Function has its own limit that it checks for.

rockstardev
  • 13,479
  • 39
  • 164
  • 296