php通過smtp郵件驗證登陸的方法
來源:易賢網(wǎng) 閱讀:1026 次 日期:2016-08-23 15:58:02
溫馨提示:易賢網(wǎng)小編為您整理了“php通過smtp郵件驗證登陸的方法”,方便廣大網(wǎng)友查閱!

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

內(nèi)網(wǎng)的系統(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程序設計有所幫助。

更多信息請查看網(wǎng)絡編程
易賢網(wǎng)手機網(wǎng)站地址:php通過smtp郵件驗證登陸的方法
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)