当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP下MAIL的另一解决方案

PHP下MAIL的另一解决方案

2019年05月20日  | 移动技术网IT编程  | 我要评论
前一段时间我接触到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);

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网