Õâ¸ö³ÌÐòÊÇÖ±½ÓÑéÖ¤ÓÊÏäÊÇ·ñÕæʵÓÐЧµÄº¯Êý£¬checkmailÊÇÖ÷º¯Êý£¬Ê¹ÓÃʱÇëÖ±½ÓʹÓü´¿É£¬×¢Ò⣺ÒòʹÓÃÁËDNSº¯Êý£¬¸Ã³ÌÐò²»ÄÜÔËÐÐÔÚWindowsϵͳ֮Ï£¬Ê¹ÓÃLinuxºÍFreeBSD¶¼²âÊÔͨ¹ý¡£
<? set_time_limit(0); if($_POST["mail"]!=""){ echo "µç×ÓÓʼþµØÖ·£º".$_POST["mail"]; if( checkmail($_POST["mail"])) echo " ¡ª <font color=green>ÓÐЧ</font>"; else echo " ¡ª <font color=red>ÎÞЧ</font>"; } ?>
<form method=post action=""> <input type=text name=mail ><input type="submit" value="¼ì²é"> </form>
<?
function server_parse($socket, $response, $line = __LINE__){ while (substr($server_response, 3, 1) != ' '){ if (!($server_response = fgets($socket, 512))){ return false; } } if (!(substr($server_response, 0, 3) == $response)){ return false; } return true; }
function checkmail($strMail){ $arrMail=explode("@",$strMail); if(! getmxrr ( $arrMail[1], $mxhosts ,$bb))return -1; if($mxhosts[0]=="")return -1;//²»ÄÜ»ñµÃÖ÷»úµÄMXÐÅÏ¢ $cc=false; for($i=0;$i<count($mxhosts);$i++){ echo $mxhosts[$i]."
"; if( $socket = @fsockopen($mxhosts[$i], 25, $errno, $errstr, 5) ){ if(server_parse($socket, "220", __LINE__)){ $cc=true; break; } } } if($cc==false)return -2;//²»ÄÜ´ò¿ªÖ÷»ú fputs($socket, "HELO ".$arrMail[1]."
"); if(!server_parse($socket, "250", __LINE__))return -3;
srand((double)microtime()*1000000); $randval = substr(md5(uniqid(rand())),0,6); fputs($socket, "MAIL FROM:<$randval@testemail.com>
"); //ʹÓÃÊÇÇ뽫testemail.com¸Ä³ÉÄãÍøÕ¾µÄÓòÃû if(!server_parse($socket, "250", __LINE__))return -4;
fputs($socket, "RCPT TO:<$strMail>
"); if(!server_parse($socket, "250", __LINE__))return -5;//ÎÞЧµÄÓû§Ãû
fclose($socket); return true; } ?> |