Validating email address Edit on GitHub In category: PHP

Syntax validation(Applicable in versions: PHP 5.2+) #syntax

The best way to validate email syntax is to use filter_var().

if (filter_var('foo@example.com', FILTER_VALIDATE_EMAIL)) {
    echo 'email is correct';


filter_var() checks for syntactical correctness. A successful check does not guarantee actual existence of an address.


Remember, filter_var returns filtered string, not a boolean value, so you should cast it where appropriate.

Validating MX record #mx-record

Another aspect you can check is the presence of an MX record for the domain name. It cannot ensure you that specified address exists, but it verifies the server associated with it is capable of exchanging emails.

Comments #comments