Start Validating email address with php

Validating email address with php

With AJAX, we can call the function to validate the email address once the user clicks away from the box.

How many times have you heard of email being termed "the ultimate killer application"?

Indeed, the impact that it has made on all of our lives in such a short period of time is immeasurable.

How to check if an email address is valid in PHP: use one of the Filter functions, like this: $email1 = "[email protected]"; // not a valid email $email2 = "[email protected]"; // valid email $clean_email1 = filter_var($email1, FILTER_VALIDATE_EMAIL); // $clean_email1 = false $clean_email2 = filter_var($email2, FILTER_VALIDATE_EMAIL); // $clean_email2 = [email protected] The Filter extension was new in PHP 5.2, but is one of the unsung heroes of the language.

From cluttering up databases with invalid information, to sending newsletters or similar content to email addresses at nonexistent domains, headaches are surely going to come up from receiving fake email.

Several approaches can be taken to address the problem, depending on the level of complexity desired for the validation itself.

If the application is going to make use of a basic level of validation, a quick-and-dirty way to handle the situation might be to implement a simple PHP function that performs pattern matching to a standardized email address format, as we have seen many times.

This is a PHP class that attempts to validate a given e-mail address at four levels: matching the address against a RFC compliant regular expression; checking whitelists and blacklists of domains with typing mistakes, disposable email addresses, and temporary and fake domains; verifying the existence of the destination SMTP server by verifying the respective DNS MX record; and connecting to that server to see if the given address is accepted as a valid recipient.