Check whether the php verification mailbox actually exists

Source: Internet
Author: User
Hello everyone, I am a beginner in php. if you have any questions, please check whether the email address actually exists during registration. thank you; environment win32 + php5.45test. php & lt ;? Phpecho & nbsp; "& lt; center & gt; & lt; br/& gt; check php to verify whether the email address actually exists.
Hello everyone, I am a beginner in php. if you have any questions, please check whether the email address actually exists during registration. thank you.

Environment win32 + php5.45

Test. php

Echo"
Check whether the email address is correct:
";
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 "you are not sure if your mailbox is correct. Is your mailbox too far away from here?
";
Return;
} Else {
Echo & quot; 22222222 & quot ";
If (! $ Result ){
Echo "the email address you entered is incorrect! :)
";
Return;
} Else {
Echo "the email address is valid!
";
}
}

?>



Email_validation.php


class email_validation_class 

//var $email_regular_expression="^([a-z0-9_] |//- |//.)+@(([a-z0-9_] |//-)+//.)+[a-z]{2,4}$"; 
var $timeout=0; 
var $localhost=""; 
var $localuser=""; 
var $hosts=0;

Function GetLine($connection) 

for($line="";;) 

if(feof($connection)) 
return(0); 
$line.=fgets($connection,100); 
$length=strlen($line); 
if($length>=2 && substr($line,$length-2,2)=="/r/n") 
return(substr($line,0,$length-2)); 



Function PutLine($connection,$line) 

return(fputs($connection,"$line/r/n")); 


Function ValidateEmailAddress($email) { 
//return(eregi($this->email_regular_expression,$email)!=0); 
//origin:
//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]);



Function ValidateEmailHost($email,$hosts=0) 

if(!$this->ValidateEmailAddress($email)) 
return(0); 
$user=strtok($email,"@"); 
$domain=strtok(""); 
if(GetMXRR($domain,$hosts,$weights)) 

$mxhosts=array(); 
for($host=0;$host $mxhosts[$weights[$host]]=$hosts[$host]; 
KSort($mxhosts); 
for(Reset($mxhosts),$host=0;$host $hosts[$host]=$mxhosts[Key($mxhosts)]; 

else 

$hosts=array(); 
if(strcmp(@gethostbyname($domain),$domain)!=0) 
$hosts[]=$domain; 

return(count($hosts)!=0); 


Function VerifyResultLines($connection,$code) 

while(($line=$this->GetLine($connection))) 

if(!strcmp(strtok($line," "),$code)) 
return(1); 
if(strcmp(strtok($line,"-"),$code)) 
return(0); 

return(-1); 


Function ValidateEmailBox($email) 

if(!$this->ValidateEmailHost($email,$hosts)) 
return(0); 
if(!strcmp($localhost=$this->localhost,"") && !strcmp($localhost=getenv("SERVER_NAME"),"") && !strcmp($localhost=getenv("HOST"),"")) 
$localhost="localhost"; 
if(!strcmp($localuser=$this->localuser,"") && !strcmp($localuser=getenv("USERNAME"),"") && !strcmp($localuser=getenv("USER"),"")) 
$localuser="root"; 
for($host=0;$host { 
if(($connection=($this->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); 
return($result); 

fclose($connection); 


return(-1); 

}; 

?> 



Share:
------ Solution --------------------
I don't understand. my idea is to check whether the format is correct at most, and then send an activation code to his mailbox like everyone else to complete the last step of registration. You want to verify it directly, unless the email service provider provides an interface for you to verify. Otherwise.
------ Solution --------------------
The authenticity of an email cannot be determined, although any email server has the mailbox list function. But most of them are not open to the outside world.
You need to activate registration via email. it looks good. But it is based on the professional ethics of the website administrator. The advertising emails you receive are like this.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.