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

yipeiwu_com6年前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获取http请求的头信息实现步骤

PHP手册提供了现成的函数: getallheaders (PHP 4, PHP 5) getallheaders — Fetch all HTTP request headers 说明...

php 代码优化的42条建议 推荐

1.如果一个方法可静态化,就对它做静态声明。速率可提升至4倍。 2.echo 比 print 快。 3.使用echo的多重参数(译注:指用逗号而不是句点)代替字符串连接。 4.在执行fo...

php如何调用webservice应用介绍

php如何调用webservice应用介绍

1.1、Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中...

php模拟post提交数据的方法

本文实例讲述了php模拟post提交数据的方法。分享给大家供大家参考。具体如下: php模拟post提交数据,用处很多,可用来网站的采集,登陆等等 这里以我项目中的论坛登录为例加以说明:...

解析isset与is_null的区别

isset和is_null啥区别,看手册上讲的话, isset和is_null的功能几乎完全”相反的一样”..是不是isset就是一个is_null的相反的别名?诶, 要说区别, 那还真...