<?
/*
This function can send emails, but will return AUTHENTIFICATION error: 502 Error: command not implemented
The error message is unknown.
*/
Function send_mail ($ to, $ subject = 'no subobject', $ body, $ smtp_acc, $ smtp_pass, $ smtp_host, $ from ){
$ Loc_host = "localhost"; // the name of the sender's computer.
// $ Smtp_acc = "info@zealotsun.com"; // Smtp-authenticated user name, similar to a fish1240@fishcat.com.cn, or fish1240
// $ Smtp_pass = "zoezhu188"; // password for Smtp authentication, which is generally equivalent to the pop3 PASSWORD
// $ Smtp_host = "mail.zealotsun.com"; // SMTP server address, similar to smtp.tom.com
// $ From = "info@zealotsun.com"; // Email address of the sender, your mail address
$ Headers = "Content-Type: text/html; charset =/" gb2312/"/r/nContent-Transfer-Encoding: base64 ";
$ Lb = "/r/n"; // linebreak
$ Hdr = explode ($ lb, $ headers); // resolved hdr
If ($ body) {$ bdy = preg_replace ("/^ /. /",".. ", explode ($ lb, $ body);} // The parsed Body
$ Smtp = array (
// 1. EHLO, expecting to return 220 or 250
Array ("EHLO". $ loc_host. $ lb, "220,250", "HELO error :"),
// 2. send Auth Login and expect to return 334
Array ("auth login". $ lb, "334", "AUTH error :"),
// 3. Send the Base64-encoded user name, and a 334 error is returned.
Array ($ smtp_acc. $ lb, "334", "AUTHENTIFICATION error :"),
// 4. Send the Base64 encoded password and expect to return 235
Array ($ smtp_pass. $ lb, "235", "AUTHENTIFICATION error :"));
// 5. Send Mail From and expect to return 250
$ Smtp [] = array ("mail from: <". $ from. ">". $ lb, "250", "mail from error :");
// 6. Send Rcpt. Expected 250
$ Smtp [] = array ("rcpt to: <". $ to. ">". $ lb, "250", "rcpt to error :");
// 7. Send DATA and expect to return 354
$ Smtp [] = array ("DATA". $ lb, "354", "DATA error :");
// 8.0. Send From
$ Smtp [] = array ("From:". $ from. $ lb ,"","");
// 8.2. Send.
$ Smtp [] = array ("To:". $ to. $ lb ,"","");
// 8.1. Sending title
$ Smtp [] = array ("Subject:". $ subject. $ lb ,"","");
// 8.3. Send other Header content
Foreach ($ hdr as $ h) {$ smtp [] = array ($ h. $ lb ,"","");}
// 8.4. Send an empty line and end Header sending
$ Smtp [] = array ($ lb ,"","");
// 8.5 send email subject
If ($ bdy) {foreach ($ bdy as $ B) {$ smtp [] = array (base64_encode ($ B. $ lb ). $ lb ,"","");}}
// 9. Sending "." indicates that the mail is over and 250 is expected to be returned.
$ Smtp [] = array (".". $ lb, "250", "DATA (end) error :");
// 10. Send Quit and exit. expected to return 221
$ Smtp [] = array ("QUIT". $ lb, "221", "QUIT error :");
// Open the smtp server port
$ Fp = @ fsockopen ($ smtp_host, 25 );
If (! $ Fp) echo "<B> Error: </B> Cannot conect to". $ smtp_host. "<br> ";
While ($ result = @ fgets ($ fp, 1024) {if (substr ($ result, 3, 1) = "") {break ;}}
$ Result_str = "";
// Send commands/data in the smtp Array
Foreach ($ smtp as $ req ){
// Send information
@ Fputs ($ fp, $ req [0]);
// Print $ req [0];
// If you want to receive the information returned by the server
If ($ req [1]) {
// Receive information
While ($ result = @ fgets ($ fp, 1024 )){
// Print $ result;
If (substr ($ result, 3, 1) = "") {break ;}
};
If (! Strstr ($ req [1], substr ($ result, 0, 3 ))){
$ Result_str. = $ req [2]. $ result. "<br> ";
}
}
}
// Close the connection
@ Fclose ($ fp );
// Print $ result_str;
Return $ result_str;
// Return $ result;
}
?>
Use str_replace to remove the line break before sending long text.