Validating an email address with PHP

Steps to validate an email address:

  1. Sanitizing the email address:
    • strtolower($emailAddress);
    • filter_var($emailAddress, FILTER_SANITIZE_EMAIL); // remove bad characters from the email.
  2. Validating the email adress:
    • filter_var($emailAddress, FILTER_VALIDATE_EMAIL);

Note: For email addresses containing Internationalized Domain Names (IDN) you need to convert it to punycode before validating the email address.