For questions about the PHP submission form automatic mail sending. To implement a function for a recently created website, you must submit a form and automatically send the form content to the specified email address. It is a stranger to PHP, but the CMS on the website background is PHP, so I had to put my head on it. I found some popular code on the Internet. Then my question is how the PHP code is connected to the form. I am posting the code. please help me. & Lt ;? Phpclasssmtp {* PublicVari questions about automatic sending of PHP submission forms.
To implement a function for a recently created website, you must submit a form and automatically send the form content to the specified email address. It is a stranger to PHP, but the CMS on the website background is PHP, so I had to put my head on it. I found some popular code on the Internet. Then my question is how the PHP code is connected to the form. I am posting the code. please help me.
Class smtp
{
/* Public Variables */
Var $ smtp_port;
Var $ time_out;
Var $ host_name;
Var $ log_file;
Var $ relay_host;
Var $ debug;
Var $ auth;
Var $ user;
Var $ pass;
/* Private Variables */
Var $ sock;
/* Constractor */
Function smtp ($ relay_host = "", $ smtp_port = 25, $ auth = false, $ user, $ pass)
{
$ This-> debug = FALSE;
$ This-> smtp_port = $ smtp_port;
$ This-> relay_host = $ relay_host;
$ This-> time_out = 30; // is used in fsockopen ()
#
$ This-> auth = $ auth; // auth
$ This-> user = $ user;
$ This-> pass = $ pass;
#
$ This-> host_name = "localhost"; // is used in HELO command
$ This-> log_file = "";
$ This-> sock = FALSE;
}
/* Main Function */
Function sendmail ($ to, $ from, $ subject = "", $ body = "", $ mailtype, $ cc = "", $ bcc = "", $ additional_headers = "")
{
$ Header = "";
$ Mail_from = $ this-> get_address ($ this-> strip_comment ($ from ));
$ Body = ereg_replace ("(^ | (\ r \ n) (\.)", "\ 1. \ 3", $ body );
$ Header. = "MIME-Version: 1.0 \ r \ n ";
If ($ mailtype = "HTML "){
$ Header. = "Content-Type: text/html \ r \ n ";
}
$ Header. = "To:". $ to. "\ r \ n ";
If ($ cc! = ""){
$ Header. = "Cc:". $ cc. "\ r \ n ";
}
$ Header. = "from: $ from <". $ from. "> \ r \ n ";
$ Header. = "Subject:". $ subject. "\ r \ n ";
$ Header. = $ additional_headers;
$ Header. = "Date:". date ("r"). "\ r \ n ";
$ Header. = "X-Mailer: By Redhat (PHP/". phpversion (). ") \ r \ n ";
List ($ msec, $ sec) = explode ("", microtime ());
$ Header. = "Message-ID: <". date ("YmdHis", $ sec ). ". ". ($ msec * 1000000 ). ". ". $ mail_from. "> \ r \ n ";
$ TO = explode (",", $ this-> strip_comment ($ ));
If ($ cc! = ""){
$ TO = array_merge ($ TO, explode (",", $ this-> strip_comment ($ cc )));
}
If ($ bcc! = ""){
$ TO = array_merge ($ TO, explode (",", $ this-> strip_comment ($ bcc )));
}
$ Sent = TRUE;
Foreach ($ TO as $ rcpt_to ){
$ Rcpt_to = $ this-> get_address ($ rcpt_to );
If (! $ This-> smtp_sockopen ($ rcpt_to )){
$ This-> log_write ("Error: Cannot send email to". $ rcpt_to. "\ n ");
$ Sent = FALSE;
Continue;
}
If ($ this-> smtp_send ($ this-> host_name, $ mail_from, $ rcpt_to, $ header, $ body )){
$ This-> log_write ("E-mail has been sent to <". $ rcpt_to. "> \ n ");
} Else {
$ This-> log_write ("Error: Cannot send email to <". $ rcpt_to. "> \ n ");
$ Sent = FALSE;
}
Fclose ($ this-> sock );
$ This-> log_write ("Disconnected from remote host \ n ");
}
Echo"
";
Echo $ header;
Return $ sent;
}
/* Private Functions */
Function smtp_send ($ helo, $ from, $ to, $ header, $ body = "")
{
If (! $ This-> smtp_putcmd ("HELO", $ helo )){
Return $ this-> smtp_error ("sending HELO command ");
}
# Auth
If ($ this-> auth ){
If (! $ This-> smtp_putcmd ("auth login", base64_encode ($ this-> user ))){
Return $ this-> smtp_error ("sending HELO command ");
}
If (! $ This-> smtp_putcmd ("", base64_encode ($ this-> pass ))){
Return $ this-> smtp_error ("sending HELO command ");
}
}
#
If (! $ This-> smtp_putcmd ("MAIL", "from: <". $ from. "> ")){
Return $ this-> smtp_error ("sending MAIL from command ");