Home > Backend Development > PHP Tutorial > Comprehensive test of email effectiveness_PHP tutorial

Comprehensive test of email effectiveness_PHP tutorial

WBOY
Release: 2016-07-13 17:31:32
Original
1331 people have browsed it

Generally, we often hope that friends who visit your website can leave emails
But many people will type casually, causing trouble for administrators.
The following class can check online whether the email is a valid email (whether it exists or not) )

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

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 ) ==="rn")
return(substr($line,0,$length-2));
}
}

Function PutLine($connection,$line)
{
return(fputs($connection,"$linern"));
}

Function VerifyRule($email)
{
return(eregi($this- > ;email_regular_expression,$email)!=0);
}

Function ValidateEmailHost($email,$hosts=0)
{
if(!$this->VerifyRule( $ 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); > ;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")



http://www.bkjia.com/PHPjc/509063.html

www.bkjia.com

true

TechArticleGenerally, we often hope that friends who visit your website can leave an email, but many people will type it casually, causing administrators to For troubles, the following class can check online whether the Email is a valid Email...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template