This code replicates online tools that let you check if an email address is valid. First it checks if the email format is correct, then looks up and prints the mx records. All nicely formatted with fancy words that in the end prints whether the email address valid or invalid.
<?php
$email = "[email protected]";
print("Checking: $email<br>");
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$", $email)) {
print("Format Test: PASSED<br>");
print("Online host verification Test...<br><br>");
print("MX Records for: $email<br>");
list($alias, $domain) = split("@", $email);
if (checkdnsrr($domain, "MX")) {
getmxrr($domain, $mxhosts);
foreach($mxhosts as $mxKey => $mxValue){
print(" $mxValue<br>");
}
print("Online host verification Test: PASSED<br><br>");
print("Email Status: VALID");
} else {
print(" No records found.<br>");
print("Online host verification Test: FAILED<br><br>");
print("Email Status: INVALID");
}
} else {
print("Format Test: FAILED<br><br>");
print("Invalid email address provided.<br><br>");
print("Email Status: INVALID");
}
?>