Live Email Validation

Here’s a handy bit of PHP code that will take the email variable, lookup the mail server for the domain, log into the mail server and see if it will accept delivery for that address.[code=php](.*)/’, $_REQUEST[’email’], -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$email = array_pop ($split);
$split = explode (“@”, $email);
$domain = $split[1];

getmxrr ($domain, $a, $b);
if ($a) {
foreach ($a as $key => $val) {
$c[$b[$key]] = $val;
}
ksort ($c);
} else {
$c[0] = $domain;
}

$fp = fsockopen (array_shift($c), 25, $errno, $errstr, 30);
$return = fgets ($fp, 1024);
fputs ($fp, “helo none.com\r\n”);
$return = fgets ($fp, 1024);
fputs ($fp, “mail from: \r\n”);
$return = fgets ($fp, 1024);
fputs ($fp, “rcpt to:<" . $email . ">\r\n”);
$return = fgets ($fp, 1024);
fputs ($fp, “quit”);

fclose($fp);

if (substr($return, 0, 3) > 250) {
echo “Bad email”;
} else {
echo “Good email”;
}
?>[/code]Okay, okay… the truth is I just got done adapting the GeSHi syntax highlighter into a WordPress plug-in and wanted to make sure it worked, so I needed to post some code of some sort. 🙂

Update

Seems to work pretty well if I do say so myself…

2 thoughts on “Live Email Validation”

Leave a Reply

Your email address will not be published. Required fields are marked *