带有从IIS发送附件的PHP mail()将文件附加为.bin?

时间:2011-10-31 16:44:39

标签: php email iis

此脚本适用于我的Linux机器,但不适用于我的IIS服务器。 邮件确实发送,但邮件内容为空,附件最终为.bin文件。

// Function to attach a file to an email
function mail_attachment($to, $subject, $message, $from, $file, $filename) {

  $content = chunk_split(base64_encode(file_get_contents($file))); 
  $uid = md5(uniqid(time())); 
  $header = "From: ".$from."\r\n"
      ."MIME-Version: 1.0\r\n"
      ."Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"
      ."This is a multi-part message in MIME format.\r\n" 
      ."--".$uid."\r\n"
      ."Content-type:text/html; charset=iso-8859-1\r\n"
      ."Content-Transfer-Encoding: 7bit\r\n\r\n"
      .str_replace("\n.", "\n..", $message)."\r\n\r\n"
      ."--".$uid."\r\n"
      ."Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"
      ."Content-Transfer-Encoding: base64\r\n"
      ."Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"
      .$content."\r\n\r\n"
      ."--".$uid."--"; 
  return mail($to, $subject, "", $header);
}

这就是它的召唤方式:

mail_attachment($mailto, $subject, $message, 
                $from, $_FILES['attachment']['tmp_name'], 
                $_FILES['attachment']['name']);

0 个答案:

没有答案