当前位置:K88软件开发文章中心编程语言PHPPHP01 → 文章内容

PHP下MAIL发信的另一种解决方案

减小字体 增大字体 作者:佚名  来源:翔宇亭IT乐园  发布时间:2019-1-3 0:56:23

:2011-05-23 08:57:16

本文作者曾经接触到DECTru64Unix,并在上面装了PHP+APACHE,可以用提供的mail函数始终不能正常发信,于是作者自编了一个函数,它利用UNIX下的管道和PHP的SOCK函数进行发信,经过实验非常驻成功。

下面是此函数原代码。

functionmymail($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,dMH:i:sY")."".
"From:$from".
"To:$mto".
"Cc:$mcc".
"Subject:$msubject".
"Status:".
"X-Status:".
"X-Mailer:MYEmailInterface".
"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);
}


PHP下MAIL发信的另一种解决方案