Php uses sock technology to send emails. Fast !!
The code is as follows:
Function send_mail ($ to, $ subject, $ body)
{
//// // Smtp information, which can be modified to your ,//////////
$ Loc_host = "longbill"; // The name of the email sending computer.
$ Smtp_acc = "longbill. mail"; // user name for Smtp Authentication,
$ Smtp_pass = "longbill"; // password for Smtp Authentication,
$ Smtp_host = "smtp.163.com"; // SMTP server address,
$ From = "longbill.mail@163.com"; // corresponds to smtp information, otherwise it will fail
/// // After Smtp information is complete //////////////////////// //////////
$ Headers = "Content-Type: text/plain; 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 (base64_encode ($ smtp_acc). $ lbs, "334", "AUTHENTIFICATION error :"),
// 4. send the Base64 encoded password and expect to return 235
Array (base64_encode ($ smtp_pass). $ lbs, "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"Error:Cannot conect to ". $ smtp_host ."
";
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]);
// If you want to receive the information returned by the server
If ($ req [1])
{
// Receive information
While ($ result = @ fgets ($ fp, 1024 ))
{
If (substr ($ result, 3, 1) = "") {break ;}
}
If (! Strstr ($ req [1], substr ($ result, 0, 3 )))
{
$ Result_str. = $ req [2]. $ result ."
";
}
}
}
// Close the connection
@ Fclose ($ fp );
If ($ result_str = "") {return "sent successfully !! ";}Else {return $ result_str ;}
}