loading...

Email Address Format, PHP filter_var Function And RFC 5321

hakan profile image Hakan Torun ・1 min read

The email address standarts is set by Rfc 5321. But in practice, things change a bit. Rfc5321 tells us that an email address might look like this:

local-part@domain

The domain part can be any domain or sub-domain, or even a local domain that is not tld. But there are the following restrictions for the local part.

- A-Z, a-z latin letters
- 0-9 digits
- Not to be the first and last character, dot (.) character
- Special characters !#$%&'*+-/=?^_`{|}~

We are familiar with the - and _ characters between special characters, but other special characters are not common at all. While Google's email service does not allow special characters from popular email services, Microsoft's email service allows only - and _ special characters. For a different service, the following address may be possible.

john`doe{software-developer}@domain.sub-domain.com

When the PHP filter_var function is used to controlling the mail address format

filter_var('john`doe{software-developer}@domain.sub domain.com',FILTER_VALIDATE_EMAIL)

This function will not return a false for the format described in Rfc 5321. But if the domain part is gmail, we will accept an email address that should not be, because the gmail implementation is different. When you try to verify with a non-standard library or a different method, things will be unbearable. In a possible scenario, a validation for popular email services will fail for another email service implemented according to Rfc 5321. In a multilingual system, if you have email services used in different languages ​​and languages, the result is a fully disaster!

Discussion

pic
Editor guide