techfolks php tutorials logo
email filters in php PHP Tips&Tricks

How to Validate Emails Using Filters in PHP

Using PHP Filters we can fully validate an email id and this filter option requires PHP 5 version.

Below is the code for validating emails in PHP using filters, along with using explode and foreach loop and then inserting the correct emails in the mysql database. Multiple emails validation.

Validate Emails Using Filters in PHP

//Validate bulk emails using filters with foreach loop and insert them in a table 
$email_array = explode(";",$email);
 foreach ($email_array as $email_result){
if (filter_var($email_result, FILTER_VALIDATE_EMAIL)  == TRUE) {
	echo $email_result.' is Valid Email Address '."

$db = mysql_select_db("validate", $con);

$query =  "INSERT INTO email(email,status) values('$email_result','ok')";
$res = mysql_query($query);


	echo $email_result.' Invalid Email Address'."