function verifyemail_validateemail($email) { if (!preg_match("/^([\w|\.|\-|_]+)@([\w||\-|_]+)\.([\w|\.|\-|_]+)$/i", $email)) { return false; exit; } return true; } function verifyemail_validatehost($email, $return_mxhost=0) { if (!verifyemail_validateemail($email)) { return false; exit; } list($local,$domain) = explode("@",$email,2); $mxhosts = array(); if(!checkdnsrr($domain, "MX") || !getmxrr($domain, $mxhosts)) { return false; exit; } if ($return_mxhost) { return $mxhosts; exit; } return true; } function verifyemail_validateexists($email) { $mxhosts = verifyemail_validatehost($email, true); if (!is_array($mxhosts)) { return false; exit; } $found = false; $localhost = verifyemail_localhost(); $mxsize = sizeof($mxhosts); for($i=0; $i<$mxsize; $i++) { $socket = fsockopen($mxhosts[$i], 25); if(!$socket) continue; $foo = fgets($socket, 4096); # 220 Service ready if(!preg_match("/^220/i", $foo)) { verifyemail_closesocket($socket); continue; } fputs($socket, "HELO ".$localhost."\r\n"); $foo = fgets($socket); while (preg_match("/^220/i", $foo)) { $foo = fgets($socket, 4096); } fputs($socket, "VRFY ".$email."\r\n"); $foo = fgets($socket, 4096); # 250 Requested mail action okay, completed if(preg_match("/^250/i", $foo)) { $found = true; verifyemail_closesocket($socket); break; } # 550 Requested action not taken: mailbox unavailable [E.g., mailbox not found, no access] if(preg_match("/^550/i", $foo)) { verifyemail_closesocket($socket); continue; } fputs($socket, "MAIL FROM: <".$email.">\r\n"); $foo = fgets($socket, 4096); fputs($socket, "RCPT TO: <".$email.">\r\n"); $foo = fgets($socket, 4096); # 250 Requested mail action okay, completed # 251 User not local; will forward to if(preg_match("/^[250|251]/i", $foo)) { $found = true; verifyemail_closesocket($socket); break; } verifyemail_closesocket($socket); } return $found; } function verifyemail_closesocket($socket) { fputs($socket, "QUIT\r\n"); fclose($socket); return true; } function verifyemail_localhost() { $localhost = getenv("SERVER_NAME"); if (!strlen($localhost)) $localhost = getenv("HOST"); return $localhost; } ?>