Php verifies whether the email address actually exists

Source: Internet
Author: User
Tags strtok
Hello everyone, I am a beginner in php. if you have any questions, check whether the email address actually exists at registration. thank you.

Environment win32 + php5.45

Test. php
 
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 "is not sure whether your mailbox is correct. is your mailbox too far away from this place?
"; Return;} else {echo" 22222222 "; if (! $ Result) {echo "the email address you entered is incorrect! :)
"; Return;} else {echo" the email address is valid!
";}}?>



Email_validation.php

 =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
 
  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
  
   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); } }; ?> 
  
 



Reply to discussion (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.

The email service provider does not provide this.

The format can be verified by the client. it is difficult for you to verify the correctness of the email address.

There is no way to implement whether the mailbox actually exists, and whether the mailbox format is correct is often used
Therefore, when you send an activation email to the recipient, but no one can activate the email, you can determine whether the recipient is not interested or the email address does not exist.
However, in the past few years, mailboxes have to be combined in various _ english, so basically all mailboxes exist, but is this mailbox still in use...

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.

The service provider is not open for verification.

I really don't know this. ask the email server! In fact, sending an activation code to your mailbox is also a verification method.

In fact, if you care about whether it exists or not, if you are interested in you, you will not fill in false information.

In previous programming, for example, when writing user data, you sometimes need to check whether the Email entered by the user is authentic and valid. in the past, we could only verify whether the Email contains certain special characters, for example "@",". ",". com, etc., only to determine the legitimacy of the Email, prove that the user entered the Email format is correct, but whether this Email actually exists in the network, there is no way.


First, you need to understand the SMTP protocol.
1. SMTP works in two situations: one is to transfer an email from the client to the server, and the other is to transfer it from one server to another.
Server
2. SMTP is a request/response protocol. commands and responses are based on ASCII text and end with CR and LF characters. The response includes a response
Three-digit code of the return status
3. SMTP listens for connection requests on TCP port 25
4. connection and sending process
The SMTP protocol is not complicated (the word "simple" is clearly included). It is simple if you know Sock. But now we only use the first article to say that when we send an email to a server from a client, the email server first verifies whether the email sending address actually exists on the server.
The procedure is as follows:
Port 25 of the Connection Server (if there is no email service, the connection is white)
Send helo greetings
Send the mail from command. if 250 is returned, the server can be connected. Otherwise, the server must be verified by the sender.
Send the rcpt to command. if 250 is returned, the Email exists.
Send the quit command to exit the connection.

You can understand socket, provided by the Food Network technical team

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.