PHP下MAIL的另一解决方案
2001-05-25 16:35:23 来源:WEB开发网核心提示:前一段时间我接触到DEC Tru64 Unix 我在上面装了php+APACHE,可以用提供的mail函数始终不能正常发信,于是自编了一个函数,PHP下MAIL的另一解决方案,它利用UNIX下的管道和PHP的SOCK函数进行发信,经过实验非常驻成功
前一段时间我接触到DEC Tru64 Unix 我在上面装了php+APACHE,可以用提供的mail函数始终不能正常发信,于是自编了一个函数,它利用UNIX下的管道和PHP的SOCK函数进行发信,经过实验非常驻成功,下面是此函数原代码。
function mymail($mto,$mcc,$msubject,$mbody)
{
$from="webmaster@backhome.com.cn";
$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 'webmaster@backhome.com.cn'",'w');
fputs($sock, $headers);
fputs($sock, $content);
fputs($sock, $end);
fputs($sock, ".\n");
fputs($sock, "QUIT\n");
pclose($sock);
}
function mymail($mto,$mcc,$msubject,$mbody)
{
$from="webmaster@backhome.com.cn";
$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 'webmaster@backhome.com.cn'",'w');
fputs($sock, $headers);
fputs($sock, $content);
fputs($sock, $end);
fputs($sock, ".\n");
fputs($sock, "QUIT\n");
pclose($sock);
}
更多精彩
赞助商链接