PHP邮件发送中的换行问题

时间:2014-11-03 12:46:00

标签: php email formatting format sendmail

我在使用php发送邮件时遇到了换行问题。这里的主要问题是,换行符在带附件的邮件中不起作用,但在纯文本中看起来很好。我们正在使用IIS服务器。

 $filename = basename($file);
        $file_size = filesize($file);
        $content = chunk_split(base64_encode(file_get_contents($file))); 
        $uid = md5(uniqid(time()));
        //$from = str_replace(array("\r", "\n"), '', $from); // to prevent email injection
        $header = "From: FORM - test \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/plain; charset=iso-8859-1\r\n"
              ."Content-Transfer-Encoding: 7bit\r\n\r\n"
              .$message." 
              ".$companyinfo."\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."--";

当我们在outlook电子邮件客户端中看到它以段落类型显示时,其他客户端缺少换行符。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

如果您的电子邮件属于text/html内容类型,那么您需要使用HTML标记进行换行:

<br />

如果是普通text/plain,您只需使用

即可
\n
相关问题