Php method for verifying login via smtp mail _ php skills

Source: Internet
Author: User
This article mainly introduces php login methods through smtp mail verification, involving php connection, read/write, verification, and other related operation skills for SMTP mail servers through socket, for more information, see the example in this article. We will share this with you for your reference. The details are as follows:

Intranet systems use email accounts to log on to the same account. Therefore, the following procedures are available:


/*** Login via email verification * here you need to understand that the user name is with a domain name: 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"); // indicates the identity. here, mystore writes $ mes = fgets ($ handle); // echo $ mes; if (! $ Mes) {fclose ($ handle); return false;} $ status = explode ("", $ mes); if ($ status [0]! = 250) {// server HELO failure 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) {// request verification login failure 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 ;}}

The above is the php method for verifying login via smtp mail _ php skills. For more information, see PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.