【问题标题】:How do I fix the line issue sending an email? [duplicate]如何解决发送电子邮件的线路问题? [复制]
【发布时间】:2023-03-12 03:21:02
【问题描述】:
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "From: <no-reply@siteemail.net>\r\n";

$to = "myemail@gmail.com";
$subject = $_POST['subject'];
$body = $_POST['body'];

mail($to, $subject, $body, $headers);

这是我输入的内容:“ 测试 2

嘿嘿

#

Cya, 托尼”

但是当它发送电子邮件时,它写道:“Testing 2\r\n\r\nHeyo\r\n\r\nMoney\r\n\r\n#\r\nCya,\r\nTony "

我不知道如何解决这个问题,所以我来这里寻求帮助。

【问题讨论】:

    标签: php email html-email


    【解决方案1】:

    如果你使用 content-type: text/html 你必须传递给邮件函数 html 而不是纯文本。

    尝试使用&lt;br&gt; 而不是换行

    如果你想使用 \n 你应该使用 content-type: text/plain

    如果你想使用 content-type: text/html 并使用纯文本,你可以将它传递给 nl2br() 函数

    类似问题here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 1970-01-01
      • 2015-10-16
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      • 2019-10-29
      相关资源
      最近更新 更多