Many email address validators will actually validate the email address formate, but they are not validating email address domain whether the domain really exists or not. For example example@test.com. In this email the domain is not exists in the real world, but its valid formate. We can stop this by checking the MX (Mail Exchanger) for the given hostname.
function checkEmail($StrEmail){
////// Before validate mail domain check email formate
list($StrUserName,$StrHostName) = split(‘@’,$StrEmail);
$arrMx = dns_get_record($StrHostName,MX);
if($arrMx){
return true;
}else{
return false;
}
}
checkEmail(”test@test.com“); ///////// returns false
checkEmail(”test@gmail.com“); ///////// returns true
?>
Note : This will work only in linux and not work in windows but there is a option in PEAR Net DNS package.