When viewing POP3/SMTP protocols, I want to write an operation class by myself. The core is to use fsockopen and then write/receive data, which only implements the core functions, as a trainer who learns Socket operations. Refer to RFC 2449 and some code of Uebimiau, a simple Web mail system in foreign countries, but they are not copied, HOHO, and they are absolutely original. If you like it, please add it to your favorites and modify it as you like. Well, remember not to delete the reputation in the even class. It's just a couple of days of hard work.
In addition, you are welcome to give full play to it, improve or correct this class, and hope it can be used for you. The Code was not carefully debugged. Please correct the bug yourself, HOHO!
<? Php
/**
* Class Name: SocketPOPClient
* Function: basic operations of POP3 client
* Author: heiyeluren * Time: 2006-7-3
* Reference: RFC 2449, Uebimiau
* Authorization: BSD License
*/
Class SocketPOPClient
{
Var $ strMessage = '';
Var $ intErrorNum = 0;
Var $ bolDebug = false;
Var $ strEmail = '';
Var $ strPasswd = '';
Var $ strHost = '';
Var $ intPort = 110;
Var $ intConnSecond = 30;
Var $ intBuffSize = 8192;
Var $ resHandler = NULL;
Var $ bolIsLogin = false;
Var $ strRequest = '';
Var $ strResponse = '';
Var $ arrRequest = array ();
Var $ arrResponse = array ();
//---------------
// Basic operations
//---------------
// Constructor
Function SocketPOP3Client ($ strLoginEmail, $ strLoginPasswd, $ strPopHost = '', $ intPort = '')
{
$ This-> strEmail = trim (strtolower ($ strLoginEmail ));
$ This-> strPasswd = trim ($ strLoginPasswd );
$ This-> strHost = trim (strtolower ($ strPopHost ));
If ($ this-> strEmail = ''| $ this-> strPasswd = '')
{
$ This-> setMessage ('email address or Passwd is empty', 1001 );
Return false;
}
If (! Preg_match ("/^ [w-] (. [w-]) * @ [w-] (. [w-]) $/I ", $ this-> strEmail ))
{
$ This-> setMessage ('email address invalid', 1002 );
Return false;
}
If ($ this-> strHost = '')
{
$ This-> strHost = substr (strrchr ($ this-> strEmail, "@"), 1 );
}
If ($ intPort! = '')
{
$ This-> intPort = $ intPort;
}
$ This-> connectHost ();
}
// Connect to the server
Function connectHost ()
{
If ($ this-> bolDebug)
{
Echo "Connection". $ this-> strHost. "... rn ";
}
If (! $ This-> getIsConnect ())