How To Bulk Verify Email Address online using PHP Code

Authors: CodeToday | PHP Code | Views: 513 | Posted: 03 AM: 09/19/2017

You have a list of email addresses but you do not know if they are alive or dead?. Building a quality email address list is essential to advertising, you can use the software to test them but you have to pay to buy it.

Today I will guide you how to bulk verify email address online using PHP Code completely free.

BootsTrap Css & Jquery Library

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

HTML

<form action="" method="post" class="form-horizontal">
<div class="form-group">
<textarea  class="form-control" rows="5" name="emails"   placeholder="Put each email on new line" required><?=$_POST['emails']?></textarea>
</div>
<div class="form-group">
<button class="btn btn-info" type="submit" name="submit"><i class="glyphicon glyphicon-search"></i> Verify Email Address</button>
</div>
</form>

PHP Source Code

<?
if(isset($_POST['submit'])) {
	
$emails= explode("
",$_POST['emails']);

	foreach($emails as $email) { $i++;
	?>
		<script>
			$(document).ready(function(){   
					$('#ajax<?=$i?>').load('verify.php?email=<?=$email?>');
			});
		</script>
	 	<p id = "ajax<?=$i?>"><?=$email?></p>	
	<?	
	}
}
?>

verify.php

<?php
echo verifyEmail($_GET['email'], '[email protected]');

function verifyEmail($toemail, $fromemail, $getdetails = false){
	$email_arr = explode("@", $toemail);
	$domain = array_slice($email_arr, -1);
	$domain = $domain[0];

	// Trim [ and ] from beginning and end of domain string, respectively
	$domain = ltrim($domain, "[");
	$domain = rtrim($domain, "]");

	if( "IPv6:" == substr($domain, 0, strlen("IPv6:")) ) {
		$domain = substr($domain, strlen("IPv6") + 1);
	}

	$mxhosts = array();
	if( filter_var($domain, FILTER_VALIDATE_IP) )
		$mx_ip = $domain;
	else
		getmxrr($domain, $mxhosts, $mxweight);

	if(!empty($mxhosts) )
		$mx_ip = $mxhosts[array_search(min($mxweight), $mxhosts)];
	else {
		if( filter_var($domain, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ) {
			$record_a = dns_get_record($domain, DNS_A);
		}
		elseif( filter_var($domain, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ) {
			$record_a = dns_get_record($domain, DNS_AAAA);
		}

		if( !empty($record_a) )
			$mx_ip = $record_a[0]['ip'];
		else {

			$result   = $toemail." <span class = 'glyphicon glyphicon-remove'></span> Invalid";
			$details .= "No suitable MX records found.";

			return ( (true == $getdetails) ? array($result, $details) : $result );
		}
	}
	
	$connect = @fsockopen($mx_ip, 25); 
	if($connect){ 
		if(preg_match("/^220/i", $out = fgets($connect, 1024))){
			fputs ($connect , "HELO $mx_ip"); 
			$out = fgets ($connect, 1024);
			$details .= $out;
 
			fputs ($connect , "MAIL FROM: <$fromemail>"); 
			$from = fgets ($connect, 1024); 
			$details .= $from;

			fputs ($connect , "RCPT TO: <$toemail>"); 
			$to = fgets ($connect, 1024);
			$details .= $to;

			fputs ($connect , "QUIT"); 
			fclose($connect);

			if(!preg_match("/^250/i", $from) || !preg_match("/^250/i", $to)){
				$result = $toemail." <span class = 'glyphicon glyphicon-remove'></span> Invalid"; 
			}
			else{
				$result = $toemail." <span class = 'glyphicon glyphicon-ok'></span> Valid";
			}
		} 
	}
	else{
		$result = $toemail." <span class = 'glyphicon glyphicon-remove'></span> Invalid";
		$details .= "Could not connect to server";
	}
	if($getdetails){
		return array($result, $details);
	}
	else{
		return $result;
	}
}
?>

After completing the above steps, you will get the results as below:

How To Bulk Verify Email Address online using PHP Code

If you have any questions, please leave a message below