DEV Community

Hakan Torun
Hakan Torun

Posted on

2

Email Address Format, PHP filter_var Function And RFC 5321

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!

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay