php通过smtp邮件验证登陆的方法

yipeiwu_com5年前PHP代码库

本文实例讲述了php通过smtp邮件验证登陆的方法。分享给大家供大家参考,具体如下:

内网的系统为了统一账号,都采用用邮件账号登陆的方式,所以有了以下程序

/**
* 通过邮件 验证登陆
* 这里要明白的是用户名是 带域名的:aaa@163.com
*/
function valideEmailLogin($user, $pass, $smtp_server= 'smtp.163.com', $port=25)
{
$handle = fsockopen($smtp_server, $port);
if(!$handle)
return false;
$mes = fgets($handle);
//echo $mes;
if(!$mes){
fclose($handle);
return false;
}
$status = explode(" ",$mes);
if($status[0] != 220) { //链接服务器失败
fclose($handle);
return false;
}
fwrite($handle, 'HELO mystore'."\r\n"); //表明身份,这里的mystore是随便写的
$mes = fgets($handle);
//echo $mes;
if(!$mes){
fclose($handle);
return false;
}
$status = explode(" ",$mes);
if($status[0] != 250) { //服务器HELO失败
fclose($handle);
return false;
}
fwrite($handle, 'AUTH LOGIN'."\r\n");
$mes = fgets($handle);
//echo $mes;
if(!$mes){
fclose($handle);
return false;
}
$status = explode(" ",$mes);
if($status[0] != 334) { //请求验证登陆失败
fclose($handle);
return false;
}
fwrite($handle,base64_encode($user)."\r\n");
$mes = fgets($handle);
//echo $mes;
if(!$mes){
fclose($handle);
return false;
}
$status = explode(" ",$mes);
if($status[0] != 334) { //验证用户名失败
fclose($handle);
return false;
}
fputs($handle,base64_encode($pass)."\r\n"); 
$mes = fgets($handle);
//echo $mes;
if(!$mes){
fclose($handle);
return false;
}
$status = explode(" ",$mes);
fclose($handle);
if($status[0] != 235) { //验证密码失败
return false;
}else{
return true;
}
}

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php socket用法总结》、《PHP网络编程技巧总结》、《PHP数组(Array)操作技巧大全》、《PHP数学运算技巧总结》、《PHP图形与图片操作技巧汇总》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家PHP程序设计有所帮助。

相关文章

php输出金字塔的2种实现方法

本文实例讲述了php输出金字塔的2种实现方法。分享给大家供大家参考。具体分析如下: 下面给大家总结了两种实现金字塔打印的方法,一种是利用了自定义函数,另一种是利用了for循环了,其实两都...

php函数之子字符串替换 str_replace

str_replace — 子字符串替换 [str_replace]mixed str_replace ( mixed $search , mixed...

提高define性能的php扩展hidef的安装和使用

提高define性能的php扩展hidef的安装和使用

官网:http://pecl.php.net/package/hidef简介:  Allow definition of user defined constants in simple...

PHP答题类应用接口实例

本文实例讲述了PHP答题类应用接口的实现方法。分享给大家供大家参考。具体实现方法如下: question_get.php文件如下: 复制代码 代码如下:<?php ...

php 向访客和爬虫显示不同的内容

听说本方法会触犯搜索引擎的一些操作原则, 有可能被被各搜索引擎处罚, 甚至删除网站. 所以我刚刚已经撤下这样的处理, 直到确定其不属于作弊. 有魄力的朋友可以继续使用, 但后果自负. 本...