I used to use a function like this, but it proves to be too unreliable so I discontinued using it:
Code:
public function _email_core($email)
{
# Check email syntax with regex
$emailClean = 1;
if (preg_match('/^([a-zA-Z0-9\._\+-]+)\@((\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,7}|[0-9]{1,3})(\]?))$/', $email, $matches))
{
$user = $matches[1];
$domain = $matches[2];
# Check availability of DNS MX records
if (function_exists('getmxrr'))
{
# Construct array of available mailservers
if(getmxrr($domain, $mxhosts, $mxweight))
{
for($i=0;$i<count($mxhosts);$i++)
{
$mxs[$mxhosts[$i]] = $mxweight[$i];
}
asort($mxs);
$mailers = array_keys($mxs);
}
elseif(checkdnsrr($domain, 'A'))
{
$mailers[0] = gethostbyname($domain);
}
else
{
$mailers=array();
}
$total = count($mailers);
if($total <= 0)
{
//$emailClean = 0;
return FALSE;
}
}
else
{
//debug only for localhost (wampserver)
return TRUE;
}
}
else
{
return FALSE;
}
return TRUE;
}