Home Backend Development PHP Tutorial php应验邮箱是否真实存在

php应验邮箱是否真实存在

Jun 13, 2016 pm 01:17 PM
amp connection email quot return

php验证邮箱是否真实存在
大家好,我是php新手,现在有个问题想请教大家,就是注册时验证该email地址是否真的存在,谢谢 

环境win32+php5.45

test.php

PHP code
<!--

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) )"; 
        return; 
    }else{ 
            echo "22222222";
        if(!$result){ 
            echo "您输入的信箱地址是不正确的! :)<br>"; 
            return; 
        }else{
            echo "邮箱合法!<br>"; 
        } 
    }

?>

Copy after login



email_validation.php

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
 
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<count ksort for else if return function verifyresultlines while>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<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: ") && $this->VerifyResultLines($connection,"250")>0 && $this->PutLine($connection,"RCPT TO: ") && ($result=$this->VerifyResultLines($connection,"250"))>=0) 
{ 
fclose($connection); 
return($result); 
} 
fclose($connection); 
} 
} 
return(-1); 
} 
}; 

?> 


 <div class="clear">
                 
              
              
        
            </div></count></count>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use email, smtplib, poplib, imaplib modules to send and receive emails in Python How to use email, smtplib, poplib, imaplib modules to send and receive emails in Python May 16, 2023 pm 11:44 PM

The journey of an email is: MUA: MailUserAgent - Mail User Agent. (i.e. email software similar to Outlook) MTA: MailTransferAgent - Mail transfer agent, which is those email service providers, such as NetEase, Sina, etc. MDA: MailDeliveryAgent - Mail delivery agent. A server of the Email service provider sender->MUA->MTA->MTA->if

Detailed explanation of the usage of return in C language Detailed explanation of the usage of return in C language Oct 07, 2023 am 10:58 AM

The usage of return in C language is: 1. For functions whose return value type is void, you can use the return statement to end the execution of the function early; 2. For functions whose return value type is not void, the function of the return statement is to end the execution of the function. The result is returned to the caller; 3. End the execution of the function early. Inside the function, we can use the return statement to end the execution of the function early, even if the function does not return a value.

What does CONNECTION_REFUSED mean? What does CONNECTION_REFUSED mean? Jul 31, 2023 pm 02:48 PM

CONNECTION_REFUSED is a network connection error that usually occurs when trying to connect to a remote server. When a client device attempts to establish a network connection with a server, and the server rejects the connection request, a CONNECTION_REFUSED error is returned. Common reasons include: the server is not started, the server cannot accept more connection requests, the server firewall blocks the connection, etc.

How to solve connection error How to solve connection error Nov 07, 2023 am 10:44 AM

Solution: 1. Check the network connection; 2. Check the server status; 3. Clear the cache and cookies; 4. Check the firewall and security software settings; 5. Try to use other networks, etc.

What is the execution order of return and finally statements in Java? What is the execution order of return and finally statements in Java? Apr 25, 2023 pm 07:55 PM

Source code: publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#Output The output of the above code can simply conclude: return is executed before finally. Let's take a look at what happens at the bytecode level. The following intercepts part of the bytecode of the case1 method, and compares the source code to annotate the meaning of each instruction in

PHP Warning: mysqli_connect(): (HY000/2002): Solution to Connection refused PHP Warning: mysqli_connect(): (HY000/2002): Solution to Connection refused Jun 23, 2023 am 08:54 AM

If you encounter the following error message when using PHP to connect to a MySQL database: PHPWarning:mysqli_connect():(HY000/2002):Connectionrefused, then you can try to solve this problem by following the steps below. To confirm whether the MySQL service is running normally, you should first check whether the MySQL service is running normally. If the service is not running or fails to start, it may cause a connection refused error. you can

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

What coin is AMP? What coin is AMP? Feb 24, 2024 pm 09:16 PM

What is AMP Coin? The AMP token was created by the Synereo team in 2015 as the main trading currency of the Synereo platform. AMP token aims to provide users with a better digital economic experience through multiple functions and uses. Purpose of AMP Token The AMP Token has multiple roles and functions in the Synereo platform. First, as part of the platform’s cryptocurrency reward system, users are able to earn AMP rewards by sharing and promoting content, a mechanism that encourages users to participate more actively in the platform’s activities. AMP tokens can also be used to promote and distribute content on the Synereo platform. Users can increase the visibility of their content on the platform by using AMP tokens to attract more viewers to view and share

See all articles