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

來源:互聯網
上載者:User

本文執行個體講述了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相關內容感興趣的讀者可查看本站專題:《php socket用法總結》、《PHP網路編程技巧總結》、《PHP數組(Array)操作技巧大全》、《PHP數學運算技巧總結》、《PHP圖形與圖片操作技巧匯總》、《php操作office文檔技巧總結(包括word,excel,access,ppt)》、《php日期與時間用法總結》、《php物件導向程式設計入門教程》、《php字串(string)用法總結》、《php+mysql資料庫操作入門教程》及《php常見資料庫操作技巧匯總》

希望本文所述對大家PHP程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.