欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php通過smtp郵件驗證登陸的方法

 更新時間:2016年05月11日 10:41:21   作者:十一文  
這篇文章主要介紹了php通過smtp郵件驗證登陸的方法,涉及php通過socket針對SMTP郵件服務器進行連接、讀寫、驗證等相關操作技巧,需要的朋友可以參考下

本文實例講述了php通過smtp郵件驗證登陸的方法。分享給大家供大家參考,具體如下:

內網的系統(tǒng)為了統(tǒng)一賬號,都采用用郵件賬號登陸的方式,所以有了以下程序

/**
* 通過郵件 驗證登陸
* 這里要明白的是用戶名是 帶域名的: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程序設計有所幫助。

相關文章

最新評論