发送email的一个问题 非法的email地址检查是很容易,可是怎么检查对方的Email是否存在?不知道该怎么弄,imap/POP3 都不懂 请指点一二,谢谢帮忙 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个比较麻烦,要先检查邮件后面的域名的DNS对应的IP是否有效然后再检查前面的邮箱名是否真的存在蛮以前做过个,记得是用下面的这个类做的貌似http://www.phpclasses.org/browse/package/13.html 网上找了一个..希望对lz有用..---------------------------------------------------------------------------------SMTP判断邮箱是否存在,检查email地址是否真实存在判断一个Email是否存在的类 作者:mlemos来源:www.fastboard.org<? /* * 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=""; 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); return(eregi("^([a-z0-9_] |\\- |\\.)+@(([a-z0-9_] |\\-)+\\.)+[a-z]{2,4}$",$email)!=0); } 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($hosts);$host++) $mxhosts[$weights[$host]]=$hosts[$host]; KSort($mxhosts); for(Reset($mxhosts),$host=0;$host<count($mxhosts);Next($mxhosts),$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<count($hosts);$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); } }; ?> ============================================================================= ----------------------------------------------------------------------------- 应用范例: ============================================================================= echo "<center><br/>检查电子邮件地址的正确性:<br/>"; $newmail = "[email protected]"; require("email_validation.php3"); $validator=new email_validation_class; $validator->timeout=10; if(IsSet($newemail) && strcmp($newemail,"")) { if(($result=$validator->ValidateEmailBox($newemail))<0) { echo "不能确定您的信箱是否正确. 您的信箱离这里太远了吧?<br/>"; return; } else { if(!$result) { echo "您输入的信箱地址是不正确的! :)<br/>"; return; } else echo "邮箱合法!<br/>"; } } 有一点点郁闷,上面俩个我没有调试出来http://www.phpclasses.org/browse/package/13.html 这个可以运行了,但是测试结果不对ai_ni 的代码运行不起来 呵呵 头发又掉了好几根了 简单的PHP 语法问题 图片验证码本地测试没有问题,发到服务器上就... php 跳转后表单内容如何保留? 怎么用PHP输出txt格式的文件! PHPChina(深圳)腾讯PHP培训班开始招生 能否/content/23933这样的连接定向到动态页面? 还是关于imap_headers的问题 请问gd里的图像函数这么装呀? 关于session在页面之间传值的问题 PHPstorm不跳转页面 非常非常菜的问题,大家帮帮忙 FCKedior 对表格处理有BUG,如何解决
然后再检查前面的邮箱名是否真的存在
蛮以前做过个,记得是用下面的这个类做的貌似
http://www.phpclasses.org/browse/package/13.html
作者:mlemos
来源:www.fastboard.org<?
/*
* 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="";
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);
return(eregi("^([a-z0-9_] |\\- |\\.)+@(([a-z0-9_] |\\-)+\\.)+[a-z]{2,4}$",$email)!=0);
}
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($hosts);$host++)
$mxhosts[$weights[$host]]=$hosts[$host];
KSort($mxhosts);
for(Reset($mxhosts),$host=0;$host<count($mxhosts);Next($mxhosts),$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<count($hosts);$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);
}
};
?>
=============================================================================
-----------------------------------------------------------------------------
应用范例:
=============================================================================
echo "<center><br/>检查电子邮件地址的正确性:<br/>";
$newmail = "[email protected]";
require("email_validation.php3");
$validator=new email_validation_class;
$validator->timeout=10;
if(IsSet($newemail) && strcmp($newemail,""))
{
if(($result=$validator->ValidateEmailBox($newemail))<0)
{
echo "不能确定您的信箱是否正确. 您的信箱离这里太远了吧?<br/>";
return;
}
else
{
if(!$result)
{
echo "您输入的信箱地址是不正确的! :)<br/>";
return;
}
else
echo "邮箱合法!<br/>";
}
}
http://www.phpclasses.org/browse/package/13.html 这个可以运行了,但是测试结果不对
ai_ni 的代码运行不起来
呵呵 头发又掉了好几根了