Use PHP to implement POP3 mail receiving class
(Author: Chen Junqing October 18, 2000)
Now let's use PHP to implement a class for receiving letters through POP3 protocol. Some sock operation functions used in this class are not described in detail, for more information, see php. Through this instance, I believe you will feel the flexibility, convenience, and powerful functionality of sock operations in PHP like me.
First, let's illustrate some internal member variables that need to be used in this class: (these variables should be closed to the outside, however, since php does not separate the private and publice member variables of the class, we have to define them directly. This is a pity for PHP .)
1. Description of member variables
Class pop3
{
Var $ hostname = ""; // POP host name
Var $ port = 110; // The POP3 port of the host, usually port 110.
Var $ timeout = 5; // maximum timeout value for connecting to the host
Var $ connection = 0; // Save the connection to the host
Var $ state = "DISCONNECTED"; // save the current state
Var $ debug = 0; // indicates whether the debugging is in the debugging status. If yes, the debugging information is output.
Var $ err_str = ''; // if an error occurs, save the error message here.
Var $ err_no; // if an error occurs, save the error number here.
Var $ resp; // Save the server response information temporarily
Var $ apop; // indicates that password verification is required using encryption. Generally, the server does not need
Var $ messages; // number of emails
Var $ size; // The total size of each email
Var $ mail_list; // an array that stores the size of each email and its serial number on the email server.
Var $ head = array (); // The content of the mail header, array
Var $ body = array (); // body content, array;
2. Of course, some of these variables cannot fully understand how to use them through such a simple description. Next I will explain one by one the main methods in this class implementation:
Function pop3 ($ server = "192.100.100.1", $ port = 110, $ time_out = 5)
{$ This-> hostname = $ server;
$ This-> port = $ port;
$ This-> timeout = $ time_out;
Return true;
}
If you are familiar with object-oriented programming, you will know that this is the constructor of this class. When initializing this class, you can give these basic parameters: pop3 server address, port number, and the maximum timeout time for connecting to the server. Generally, you only need to provide the POP3 server address.
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.