手机
当前位置:查字典教程网 >编程开发 >php教程 >php通过smtp邮件验证登陆的方法
php通过smtp邮件验证登陆的方法
摘要:本文实例讲述了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'."rn"); //表明身份,这里的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'."rn"); $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)."rn"); $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)."rn"); $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通过smtp邮件验证登陆的方法】相关文章:

php统计数组元素个数的方法

php函数重载的替代方法

php删除指定目录的方法

php转换颜色为其反色的方法

php按单词截取字符串的方法

php简单实现多字节字符串翻转的方法

php查询whois信息的方法

PHP正则验证Email的方法

php准确获取文件MIME类型的方法

php 类自动载入的方法

精品推荐
分类导航