class MailService
{
/**
*
* Verify if a given email is valid looking for is MX record
*/
public function verifyMail($email)
{
list($user, $domain) = explode('@', $email);
$info = ['user' => $user, 'domain' => $domain, 'ip' => null, 'mx' => null];
$result['address'] = $email;
//TODO - Verify common names
$result['did_you_mean'] = null;
//Look for MX record
$result['is_valid'] = dns_check_record($domain, "MX");
if ($result['is_valid']) {
//Get ip and mx address
$a = dns_get_record($domain, DNS_A);
$mx = dns_get_record($domain, DNS_MX);
if (isset($a[0]['ip'])) {
$info['ip'] = $a[0]['ip'];
}
if (isset($mx[0]['target'])) {
$info['mx'] = $mx[0]['target'];
}
}
$result['info'] = $info;
//Return as object
return (Object) $result;
}
}
PHP - Verify if a given email is valid looking for his MX record
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.