php でメール アドレスが本当に存在するかどうかを確認します
皆さん、こんにちは。php を初めて使用します。登録時にメール アドレスが本当に存在するかどうかを確認する必要があります。ありがとうございます。
環境 win32+php5.45
test.php
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <?php echo "<center><br/>检查电子邮件地址的正确性:<br/>"; require("email_validation.php"); $newmail = "283285993@qq.com"; $validator=new email_validation_class; $validator->timeout=10; //if(IsSet($newemail) && strcmp($newemail,"")){ if( ($result=$validator->ValidateEmailBox($newmail) )<0){ echo "不能确定您的信箱是否正确. 您的信箱离这里太远了吧?<br/>"; return; }else{ echo "22222222"; if(!$result){ echo "您输入的信箱地址是不正确的! :)<br/>"; return; }else{ echo "邮箱合法!<br/>"; } } ?>
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> クラス email_validation_class { //var $email_正規表現="^([a-z0-9_] |//- |//.)+@(([a-z0-9_] |//-)+//.)+[a-z] {2,4}$"; var $timeout=0; var $localhost=""; var $localuser=""; var $hosts=0; 関数 GetLine($connection) { for($line="";;) { if(feof($connection)) リターン(0); $line.=fgets($connection,100); $length=strlen($line); if($length>=2 && substr($line,$length-2,2)=="/r/n") return(substr($line,0,$length-2)); } } 関数 PutLine($connection,$line) { return(fputs($connection,"$line/r/n")); } 関数 ValidateEmailAddress($email) { //return(eregi($this->email_正規表現,$email)!=0); //起源: //return(eregi("^([a-z0-9_] |//- |//.)+@(([a-z0-9_] |//-)+//.)+[a-z] {2,4}$",$email)!=0); //return preg_match("/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-] +)*(.[a-z]{2,3})$/i", $_REQUEST[$email]); return preg_match("/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+) *(.[a-z]{2,3})$/", $_REQUEST[$email]); } 関数 ValidateEmailHost($email,$hosts=0) { if(!$this->ValidateEmailAddress($email)) リターン(0); $user=strtok($email,"@"); $domain=strtok(""); if(GetMXRR($domain,$hosts,$weights)) { $mxhosts=array(); for($host=0;$host<count ksort for if return verifyresultlines while>GetLine($connection))) { if(!strcmp(strtok($line," "),$code)) 戻り値(1); if(strcmp(strtok($line,"-"),$code)) リターン(0); } 戻り値(-1); } 関数 ValidateEmailBox($email) { if(!$this->ValidateEmailHost($email,$hosts)) リターン(0); if(!strcmp($localhost=$this->localhost,"") && !strcmp($localhost=getenv("SERVER_NAME"),"") && !strcmp($localhost=getenv("HOST")," ")) $localhost="ローカルホスト"; if(!strcmp($localuser=$this->localuser,"") && !strcmp($localuser=getenv("USERNAME"),"") && !strcmp($localuser=getenv("USER")," ")) $localuser="ルート"; for($host=0;$host<count if>timeout ? fsockopen($hosts[$host],25,$errno,$error,$this->timeout) : fsockopen($hosts[$host],25) ))) { if($this->VerifyResultLines($connection,"220")>0 && $this->PutLine($connection,"HELO $localhost") && $this->VerifyResultLines($connection,"250") )>0 && $this->PutLine($connection,"MAIL FROM: <$localuser@$localhost>") && $this->VerifyResultLines($connection,"250")>0 && $this ->PutLine($connection,"RCPT TO: <$email>") && ($result=$this->VerifyResultLines($connection,"250"))>=0) { fclose($connection); 戻り値($結果); } fclose($connection); } } 戻り値(-1); } }; ?> <div class="clear"></div></count></count>