首页 > 编程 > PHP > 正文

php判断邮件服务提供商的代码示例

2020-03-22 20:12:51
字体:
来源:转载
供稿:网友
  • php判断邮件服务提供商的代码示例:

    <?php//by Gump http://gump.me/1131.html //www.it165.net//check the valid email address, if ok return the domainfunction validate_email($email){	if(!preg_match("/^[/w/.-]{1,}/@([/da-zA-Z-]{1,}/.){1,}[/da-zA-Z-]+$/", $email))		return false;	list($prefix, $domain) = split("@", $email);	if(function_exists("getmxrr") && getmxrr($domain, $mxhosts)){		return $domain;	}elseif(@fsockopen($domain, 25, $errno, $errstr, 5)){		return $domain;	}else{		return false;	}} // getmxrr() support for Windows// if Linux installed bind-utils, this way is okey too.function re_getmxrr($hostname, &$mxhosts, &$mxweight=false) {	if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') return;	if (!is_array ($mxhosts) ) $mxhosts = array();	if (empty($hostname)) return;	$exec='nslookup -type=MX '.escapeshellarg($hostname);	@exec($exec, $output);	if (empty($output)) return;	$i=-1;	foreach ($output as $line) {		if (preg_match("/^$hostname/tMX preference = ([0-9]+), mail exchanger = (.+)$/i", $line, $parts)) {			$i++;			$mxweight[$i] = trim($parts[1]);			$mxhosts[$i] = trim($parts[2]);		}		if (preg_match('/responsible mail addr = (.+)$/i', $line, $parts)) {			$i++;			$mxweight[$i] = $i;			$mxhosts[$i] = trim($parts[1]);		}	}	return ($i!=-1);} // Defineif (!function_exists('getmxrr')) {    function getmxrr($hostname, &$mxhosts, &$mxweight=false) {        return re_getmxrr($hostname, $mxhosts, $mxweight);    }} function analysis_mail_exchanger($email){	$debug = false;	//$debug = true;	$known_provider = array(		"google_apps" => array(			"aspmx.l.google.com" => 10,			"alt1.aspmx.l.google.com" => 20,			"alt2.aspmx.l.google.com" => 30,			"aspmx2.googlemail.com" => 40,			"aspmx3.googlemail.com" => 50,		),		"google_gmail" => array(			"gmail-smtp-in-v4v6.l.google.com" => 5,			"alt1.gmail-smtp-in.l.google.com" => 10,			"alt2.gmail-smtp-in.l.google.com" => 20,			"alt3.gmail-smtp-in.l.google.com" => 30,			"alt4.gmail-smtp-in.l.google.com" => 40,		),		"microsoft_hotmail" => array(			"mx3.hotmail.com" => 5,			"mx2.hotmail.com" => 5,			"mx1.hotmail.com" => 5,			"mx4.hotmail.com" => 5,		),		"microsoft_domains" => '.hotmail.com',		"yahoo_usa" => array(			"mta7.am0.yahoodns.net" => 1,			"mta6.am0.yahoodns.net" => 1,			"mta5.am0.yahoodns.net" => 1,		),		"yahoo_china" => '.yahoo.com',		"yahoo_biz" => array(			"mx1.biz.mail.yahoo.com" => 20,			"mx5.biz.mail.yahoo.com" => 30,		),		"tencent_qq" => array(			"mx3.qq.com" => 10,			"mx2.qq.com" => 20,			"mx1.qq.com" => 30,		),		"tencent_domains" => array(			"mxdomain.qq.com" => 10,		),		"tencent_exmail" => array(			"mxbiz1.qq.com" => 5,			"mxbiz2.qq.com" => 10,		),		"netease_163" => array(			"163mx01.mxmail.netease.com" => 10,			"163mx03.mxmail.netease.com" => 10,			"163mx02.mxmail.netease.com" => 10,			"163mx00.mxmail.netease.com" => 50,		),		"netease_vip163" => array(			"vip163mx01.mxmail.netease.com" => 10,			"vip163mx00.mxmail.netease.com" => 50,		),		"netease_126" => array(			"126mx02.mxmail.netease.com" => 10,			"126mx01.mxmail.netease.com" => 10,			"126mx00.mxmail.netease.com" => 50,		),		"netease_vip126" => array(			"mx.vip.126.com" => 50,		),		"netease_yeah" => array(			"yeahmx01.mxmail.netease.com" => 10,			"yeahmx00.mxmail.netease.com" => 50,		),		"netease_free" => array(			"mx.mail.ym.163.com" => 10,		),		"netease_qiye" => array(			"qiye163mx02.mxmail.netease.com" => 10,			"qiye163mx01.mxmail.netease.com" => 50,		),		"sina_mail" => array(			"freemx.sinamail.sina.com.cn" => 5,			"freemx3.sinamail.sina.com.cn" => 10,			"freemx2.sinamail.sina.com.cn" => 10,			"freemx1.sinamail.sina.com.cn" => 10,		),		"sina_vip" => array(			"mx3.vip.sina.com" => 5,			"mx2.vip.sina.com" => 10,			"mx1.vip.sina.com" => 10,			"sinamx.vip.sina.com" => 20,		),		"sina_free" => array(			"mx.exmail.sina.com" => 10,		),		"sina_qiye" => '.sina.net',		"sohu_mail" => array(			"sohumx1.sohu.com" => 5,			"sohumx.h.a.sohu.com" => 10,		),		"sohu_vip" => array(			"mx.vip.sohu.com" => 10,		),		"sohu_free" => array(			"mx.mail.sohu.net" => 10,		),	);	if($domain = validate_email($email)){		$result = 'other';		getmxrr($domain, $mxhosts, $mxweight);		for($i=0; $i<count($mxhosts); $i++){			$mxs[strtolower($mxhosts[$i])] = $mxweight[$i];		}		asort($mxs);		//$mxs = array_keys($mxs);		if($debug){			foreach ($mxs as $key => $value) {				echo '"' . $key . '" => ' . $value . ",/r/n";			}			exit();		}else{			foreach ($known_provider as $key => $value) {				if(is_array($value)){					ksort($mxs);					ksort($value);					if($value==$mxs){						$result = $key;						break;					}				}else{  //like as ms live domains					foreach ($mxs as $k => $v) {						if(stristr($k, $value) !== FALSE){							$result = $key;							break;						}						break;  //only once					}				}			}		}	}else{		$result = 'unvalid';	}	return $result;} echo analysis_mail_exchanger('admin@gump.me');?>

    欢迎各位朋友一起来完善下其他未加入判断的邮件服务提供商!

    PHP编程

    郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

  • 发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表