使用sock技術發送郵件,無需伺服器支援。速度快! !
複製程式碼 程式碼如下:
function send_mail($to,$subject,$body)
{
/////////////Smtp訊息,可修改成你的,/// ///////
$loc_host收到 $ smtp_pass = "longbill"; //Smtp認證的密碼,
$smtp_host = "sm.163.com"; @163.com"; / /要與smtp資訊對應 ,否則會失敗
/////////////Smtp資訊完結////////////////////// /////////////
$headers = "Content-Type: text/plain; charset="gb2312"rnContent-Transfer-Encoding: base64"; "; //linebreak
$hdr = explode($ ); {
$bdy = preg_replace("/^. /","..",explode($lb,$body));
}//解析後的Body
$smtp = array(
預期返回
array("EHLO ".$loc_host.$lb,"220,250","HELO error: "),
/ $lb,"334","AUTH error:"),
//3、寄經過Base64編碼的使用者名稱,請期待回334
array(base64_encode($smtp_acc).$lb,"34 "AUTHENTIFICATION error : "),
//4、寄經過Base64編碼的密碼,並期待回235
array(base64_encode($smd_pass).$🎜> array(base64_encode($smd_pass).$🎜>
//5、寄Mail From,期待返回250
$smtp[] = array("MAIL FROM: ".$lb,"250","MAIL FROMerror: ");
//6、寄Rcpt To。期待回250
$smtp[] = array("RCPT TO: ".$lb,"250","RCPT TO error: ");
/7、送 error: ");
/7、寄送DATA,期待回354
$smtp[] = array("DATA".$lb,"354","DATA error: ");
//8.0、寄送array("From: ".$from.$lb,"","");
//8.2、送To
$smtp[] = array("To: ".$to.$lb, "","");
//8.1、寄送標題
$smtp[] = array("Subject: ".$subject.$lb,"",""); 、寄其他Header內容
foreach($hdr as $h) {$smtp[] = array($h.$lb,"","");}
//8.4、寄一空行,結束Header寄送
$smtp[] = array($lb,"","");
//8.5、發送信件主體
$bdy as $b)
{
$smtp[] = array(base64_encode($b. ).$.",",""); 🎜> //9.寄「.」表示信件結束,期待回250
$smtp[] = array(".".$lb,"250","DATA(end)error: ");
/ /10、發送Quit,退出,期待返回221
$smtp[] = array("QUIT".$lb,"221","QUIT error: ");
//打開開字> > $fp = @fsockopen($smtp_host, 25);
if (!$fp) echo "Error: Cannot conect to努> while($result = @fgets($fp, 1024))
{
if(substr($result. ="";
//發送smtp數組中的命令/資料
foreach($smtp as $req)
{
//如果需要接收伺服器回傳訊息,則
if($req[1])
{ {
if(substr($result,3,1) == "){ break; if (!strstr($req[1 ],substr($result,0,3)))
{
$result_str.=$req[2].$result }; 🎜> }
//關閉連線
@fclose($fp);
if ($result_str==""){return "成功寄送}
以上就介紹了slysoft virtual clonedrive php 用sock技術發送郵件的函數,包括了slysoft virtual clonedrive方面的內容,希望對PHP教程有興趣的朋友有所幫助。