PHP邮件换行问题 [英] PHP mail line break problem

查看:123
本文介绍了PHP邮件换行问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想格式化邮件的内容以在不同的行中显示内容。
这是我的留言内容。
\n和\r在这种情况下不起作用。它只显示一行中的所有内容。

I want to format content of the mail to show the content in different line. here is my message contetn. bu the \n and \r is not working in this case. it just shows all the content in one line.

$message = 'Thank you for using . We really appreciate your business.'."\r\n".'If you are making your payment by mail, please make the check out to "blah blah" and send it to:'."\n".'blah blah '."\n".'blah blah'."\n".'San Gabriel, CA 91776'."\n".'Please see the attached invoice in PDF format for easy saving & printing purposes.';

$attachment = chunk_split(base64_encode($pdfdoc));
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/pdf; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
mail($_POST['add6'],$subject, $message, $headers);

我该怎么做?

推荐答案

您正在告诉电子邮件客户端消息是HTML,因此CR LF组合将被视为任何其他空格。

You're telling the email client the message is HTML, so the CR LF combination will be treated like any other whitespace.

要解决此问题,请更改内容类型以显示您正在发送纯文本电子邮件

To fix this, change the content type to show you are sending a plain text email

$headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"".$eol;

或者,将您的消息转换为HTML消息-一种简单的方法是通过 nl2br 运行它,将换行符转换为< br> 标签

Alternatively, turn your message into an HTML message - an easy way to do that in your case would be to run it through nl2br to turn the newlines into <br> tags

这篇关于PHP邮件换行问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆