Send_mail class implementation
Now we will introduce the mail class I have compiled. With the above preparation knowledge, the following is the implementation.
Class member variables
Var $ lastmessage; // record the last response
Var $ lastact; // The final action, in the string format
Var $ welcome; // used after HELO. welcome
Var $ debug; // whether to display debugging information
Var $ smtp; // smtp Server
Var $ port; // smtp port number
Var $ fp; // socket handle
Among them, $ lastmessage and $ lastact are used to record the last response information and executed commands. When an error occurs, you can use them. For testing purposes, I also defined the $ debug variable. When its value is true, some execution information is displayed during the running process; otherwise, no output is provided. $ Fp is used to save the opened socket handle.
Class Construction
Function send_mail ($ smtp, $ welcome = "", $ debug = false)
{
If (empty ($ smtp) die ("SMTP cannt be NULL! ");
$ This-$ # @ 62; smtp = $ smtp;
If (empty ($ welcome ))
{
$ This-$ # @ 62; welcome = gethostbyaddr ("localhost ");
}
Else
$ This-$ # @ 62; welcome = $ welcome;
$ This-$ # @ 62; debug = $ debug;
$ This-$ # @ 62; lastmessage = "";
$ This-$ # @ 62; lastact = "";
$ This-$ # @ 62; port = "25 ";
}
This constructor mainly determines and sets some initial values. $ Welcome is used in the HELO command to tell the server user's name.
The HELO command must be a machine name. If $ welcome is not provided, the local machine name is automatically searched.