Php login through smtp authentication

Source: Internet
Author: User
Intranet systems use email accounts to log on to the same account. Therefore, the following program is used to ** log on via email verification **. here we need to understand that the user name includes a Domain Name: aaa@163.com * functionvalideEmailLogin ($ user, $ pass, $ smtp_serversmtp.163.com, $ port25) {$ handlefsoc

Intranet systems use email accounts to log on to the same account, so with the following Program/*** 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 = fsoc

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


/**
* Verify login by email
* 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) {// failed to connect to the server
Fclose ($ handle );
Return false;
}

Fwrite ($ handle, 'helo mystore'. "\ r \ n"); // indicates the identity. Here, mystore is written at will.
$ Mes = fgets ($ handle );
// Echo $ mes;
If (! $ Mes ){
Fclose ($ handle );
Return false;
}

$ Status = explode ("", $ mes );
If ($ status [0]! = 250) {// server HELO failed
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) {// login request verification failed
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) {// An error occurred while verifying the user name
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) {// password verification failed
Return false;
} Else {
Return true;
}
}

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.