I'm trying to create a script that validates syntax and MX Record to know if the email is correct.
But for some reason this isn't correct.
Any ideas?
My TXT file:
email@facebook.com
email@gmail.com
asdhiadf@fdfsdf.com
My PHP Code:
$fh = fopen('emails.txt','r');
while ($line = fgets($fh)) {
// Create the syntactical validation regular expression
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
// Presume that the email is invalid
$valid = 0;
// Validate the syntax
if (eregi($regexp, $line))
{
list($username,$domaintld) = split("@",$line);
// Validate the domain
if (getmxrr($domaintld,$mxrecords)) {
echo(1) . "--> " . $line . "<br />";
}
else {
echo (-1) . "--> " . $line . "<br />";
}
} else {
echo(0) . "--> " . $line . "<br />";
}
}
fclose($fh);