I below is the script for email validation currently I am using. Any one having idea how to validate email address more then 100 or more then 50 using multithreading/piping or any other method. I need to update our database after email validation too so that next time I need to do validation.
Is swiftmailer having some inbuild feature to send emails only valid email id ?
Code: Select all
function validate_email($email)
{
$mailparts=explode("@",$email);
$hostname = $mailparts[1];
exec("dig +short MX " . escapeshellarg($hostname),$ips);
if($ips[0] == "")
{
$strDot = '.';
$strAfterAt = substr(strstr($email, '@'), 1);
$chunks = explode($strDot, $strAfterAt);
$cntChunks = count($chunks) - 1;
$hostname = $chunks[($cntChunks-1)] . $strDot . $chunks[$cntChunks];
exec("dig +short MX " . escapeshellarg($hostname),$ips);
}
if($ips[0] == "")
{
return "NO website=getcounter=NO MX ".$ips[0];
}
else
{
// get mx addresses by getmxrr
$b_mx_avail=getmxrr( $hostname, $mx_records, $mx_weight );
$b_server_found=0;
// copy mx records and weight into array $mxs
$mxs=array();
for($i=0;$i<count($mx_records);$i++)
{
$mxs[$mx_weight[$i]]=$mx_records[$i];
}
// sort array mxs to get servers with highest prio
ksort ($mxs, SORT_NUMERIC );
reset ($mxs);
while (list ($mx_weight, $mx_host) = each($mxs) )
{
if($b_server_found == 0)
{
//try connection on port 25
$fp = @fsockopen($mx_host,25, $errno, $errstr, 2);
if($fp)
{
$ms_resp="";
// say HELO to mailserver
$ms_resp.=send_command($fp, "HELO domain.com");
// initialize sending mail
$ms_resp.=send_command($fp, "MAIL FROM:<info@domain.com>");
// try receipent address, will return 250 when ok..
$rcpt_text=send_command($fp, "RCPT TO:<".$email.">");
$ms_resp.=$rcpt_text;
if(substr( $rcpt_text, 0, 3) == "250")
{
$b_server_found=1;
return "Success=getcounter=".$rcpt_text;
}
else
return "Fail=getcounter=".$rcpt_text;
// quit mail server connection
$ms_resp.=send_command($fp, "QUIT");
fclose($fp);
}//////////End 3rd if
else
return "MX info ".$ips[0]."=getcounter=".$errno." ".$errstr;
}//////////End 2nd if
} //////////End first while
}//////////End first if
}
function send_command($fp, $out)
{
fwrite($fp, $out . "\r\n");
return get_data($fp);
}
function get_data($fp)
{
$s="";
stream_set_timeout($fp, 2);
for($i=0;$i<2;$i++)
$s.=fgets($fp, 1024);
return $s;
}