Use sock technology to send mail without server support. The speed is fast!!
Copy Code code as follows:
function Send_mail ($to, $subject, $body)
{
SMTP information that can be modified to your//////////
$loc _host = "Longbill"; The computer name of the letter, can be arbitrary
$SMTP _ACC = "Longbill.mail"; The user name of the SMTP authentication,
$SMTP _pass = "Longbill"; SMTP authenticated password,
$SMTP _host = "smtp.163.com"; SMTP server address,
$from = "longbill.mail@163.com"; To correspond with SMTP information, it will fail
SMTP Information Complete//////////////////////////////////
$headers = "Content-type:text/plain; Charset=\ "gb2312\" \r\ncontent-transfer-encoding:base64 ";
$lb = "\ r \ n"; LineBreak
$HDR = Explode ($lb, $headers); Parsed HDR
if ($body)
{
$bdy = Preg_replace ("/^\./", "...", Explode ($lb, $body));
}//the body after parsing
$SMTP = Array (
1, EHLO, look forward to return 220 or 250
Array ("EHLO". $loc _host. $lb, "220,250", "HELO Error:"),
2, send Auth Login, look forward to return 334
Array ("AUTH LOGIN". $lb, "334", "AUTH Error:"),
3, send after BASE64 encoded username, look forward to return 334
Array (Base64_encode ($smtp _acc). $lb, "334", "Authentification Error:"),
4, send the password after BASE64 encoded, look forward to return 235
Array (Base64_encode ($smtp _pass). $lb, "235", "Authentification Error:");
5, send mail from, look forward to return 250
$SMTP [] = Array ("MAIL from: <". $from. " > ". $lb," A "," MAIL from Error: ");
6, send rcpt to. Expect to return 250
$SMTP [] = Array ("RCPT to: <". $to. " > ". $lb," RCPT "," to Error: ");
7, send data, look forward to return 354
$SMTP [] = Array ("Data". $LB, "354", "Data error:");
8.0. Send from
$SMTP [] = Array (from: ". $from. $lb," "," ");
8.2, Send To
$SMTP [] = Array ("To:". $to. $lb, "", "");
8.1, send the title
$SMTP [] = Array ("Subject:". $subject. $lb, "", "");
8.3, send other header content
foreach ($hdr as $h) {$SMTP [] = Array ($h. $lb, "", "");}
8.4, send a blank line, end header send
$SMTP [] = Array ($lb, "", "");
8.5, send the letter subject
if ($bdy)
{
foreach ($bdy as $b)
{
$SMTP [] = Array (Base64_encode ($b. $lb). $lb, "", "" ");
}
}
9, send "." Indicates the end of the letter, expecting to return 250
$SMTP [] = Array ("."). $LB, "The", "DATA (end) Error:");
10, send quit, exit, look forward 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 an SMTP array
foreach ($smtp as $req)
{
Send a message
@fputs ($fp, $req [0]);
If a receive server returns information is required, the
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. " <br> ";
}
}
}
Close connection
@fclose ($FP);
if ($result _str== "") {return "sent successfully!!";} else {return $result _str;}
}