PHP下MAIL的另一解決方案
來源:互聯網
上載者:User
解決 前一段時間我接觸到DEC Tru64 Unix 我在上面裝了PHP+APACHE,可以用提供的mail函數始終不能正常發信,於是自編了一個函數,它利用UNIX下的管道和PHP的SOCK函數進行發信,經過實驗非常駐成功,下面是此函數原代碼。
function mymail($mto,$mcc,$msubject,$mbody)
{
$from="webmaster@backhome.com.cn";
$sign = " ";//隨你便寫些什麼
$sendmailpath="/usr/lib/sendmail";//Semdmail路徑
$bound = "========_".uniqid("BCFMail")."==_";//分界符
$headers = "MIME-Version: 1.0 ".
"Content-Type: multipart/mixed; boundary="$bound" ".
"Date: ".date("D, d M H:i:s Y ")." ".
"From: $from ".
"To: $mto ".
"Cc: $mcc ".
"Subject: $msubject ".
"Status: ".
"X-Status: ".
"X-Mailer: MY Email Interface ".
"X-Keywords: ";
$content="--".$bound." "."Content-Type:text/plain;charset="GB2312" ".$mbody.$sign." ";
$end = " "."--".$bound."-- ";
$sock = popen("$sendmailpath -t -f 'webmaster@backhome.com.cn'",'w');
fputs($sock, $headers);
fputs($sock, $content);
fputs($sock, $end);
fputs($sock, ". ");
fputs($sock, "QUIT ");
pclose($sock);
}