【问题标题】:Line break issue in PHP mail sendingPHP邮件发送中的换行问题
【发布时间】:2014-11-03 12:46:00
【问题描述】:

我在使用 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 电子邮件客户端中看到它以段落类型显示时,其他客户端缺少换行符。有什么帮助吗?

【问题讨论】:

  • 设置邮件类型,例如text/html,并把<br />标签放在\n的地方。
  • 可以在 Headers 部分使用
    标签代替 \r\n 吗?

  • 试过了,但是没有区别

标签: php email formatting format sendmail


【解决方案1】:

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

<br />

如果是简单的text/plain,你可以简单地使用

\n

【讨论】:

  • 如果我在标题部分使用
    标签,内容将完全以段落类型显示
  • 当我在发送邮件中选择附件时,问题来了,如果 nt 工作正常
猜你喜欢
  • 2017-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-05
  • 2012-12-27
  • 1970-01-01
  • 1970-01-01
  • 2013-11-21
相关资源
最近更新 更多