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