php通過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程序設計有所幫助。
相關文章
php數組函數序列之array_search()- 按元素值返回鍵名
array_search() 函數與 in_array() 一樣,在數組中查找一個鍵值。如果找到了該值,匹配元素的鍵名會被返回。如果沒找到,則返回 false2011-11-11