源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-08-05 07:07 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:php通过smtp邮件验证登陆的方法
本文实例讲述了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相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/70.htm]php socket用法总结[/url]》、《[url=http://www.1sucai.cn/Special/495.htm]PHP网络编程技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/623.htm]PHP数组(Array)操作技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/630.htm]PHP数学运算技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/455.htm]PHP图形与图片操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/339.htm]php操作office文档技巧总结(包括word,excel,access,ppt)[/url]》、《[url=http://www.1sucai.cn/Special/96.htm]php日期与时间用法总结[/url]》、《[url=http://www.1sucai.cn/Special/43.htm]php面向对象程序设计入门教程[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》、《[url=http://www.1sucai.cn/Special/84.htm]php+mysql数据库操作入门教程[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部