PHP verifies that the mailbox is real

Source: Internet
Author: User
Tags strcmp strtok
Hello everyone, I am a novice php, now there is a question to ask you, is registered to verify that the email address is really there, thank you

Environmental win32+php5.45

test.php
 
  
Check the correctness of the e-mail address:
"; 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 if your mailbox is correct. Is your mailbox too far from here?
"; Return }else{echo "22222222"; if (! $result) {echo] The email address you entered is incorrect!:)
"; Return }else{echo "Email Legal!
"; } }? >



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, ">0") && $this->putline ($connection, "HELO $localhost ") && $this->verifyresultlines ($connection," $ ") >0 && $this->putline ($connection," MAIL From: < $localuser @ $localhost >) && $this->verifyresultlines ($connection, "$") >0 && $ This->putline ($connection, "RCPT to: < $email >") && ($result = $this->verifyresultlines ($ >=0) {fclose ($connection), return ($result);} fclose ($connection); }} return (-1); }};?>
   
  
 



Reply to discussion (solution)

No, my idea is to verify that the format is correct, and then, like everyone else, send an activation code to his mailbox to complete the last step of the registration. You want to authenticate directly unless the email provider provides an interface for you to verify. Or.

Email service provider, this really does not.

Client to verify the format it's OK, if you verify the correctness of the mailbox is a bit difficult to estimate

Whether the mailbox is real there is no way we can achieve, the mailbox format is correct this is often used
So when you send an activation email to the other person, but no one to activate then the basic can be judged that the other party is not interested or the mailbox does not exist.
However, these days, mailboxes have to use a variety of _ English to combine, so basically the mailbox is there, just this mailbox is not someone still in use ...

The authenticity of email is impossible to judge, although any mail server has a mailbox list function. But most of them will not open.
You need to activate your registration with mail, it looks good. But built on the ethics of webmasters. That's how you get those ad mails.

The service provider is not open to verify it.

This really does not know, ask the mail server! In fact, you send the activation code to the mailbox, is also a validation bar.

In fact, you do not care whether it exists, he is interested in you, will not fill the false.

In previous programming, such as writing the user's data, sometimes need to confirm that the user input email is true and effective, before we can only verify that the email contains some special characters, such as "@", ".", ". com" and so on, only to judge the legality of email, Prove that the user fill in the email format is correct, but this email is really in the network, there is no way.


First of all, you need to understand the SMTP protocol.
1.SMTP is work in two cases: one is the transfer of e-mail from the client to the server, and the other from one server to another
Server
2.SMTP is a request/response protocol, and commands and responses are based on ASCII text and end with the CR and LF characters. The response includes a return
Three-bit numeric code for the back state
3.SMTP Listening for connection requests on TCP protocol Port 25th
4. Connection and sending process
The SMTP protocol is complex and uncomplicated (clearly with the word "simple"), saying simple if you know sock. But now it's just that we're using the first one, from the client to the server, when we send mail to a server, the mail server first verifies that the mailing address really exists on the server.
Here are the steps to do this:
Connect to the server's 25 port (if there is no mail service, even the Bailian)
Send Helo Greetings
Send the mail from command, if return 250 means correct, connect to this server, otherwise the server needs sender authentication.
Send RCPT TO command, if return 250 indicates that the email exists
Send the QUIT command to exit the connection

Know socket can be provided by the Web technology 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.