无法使用 PHP 邮件程序让 nl2br 工作
我正在尝试发布上一页中的一些信息,然后通过电子邮件发送出去。
从上一页发布的信息位于文本区域内,我希望当用户在该文本区域中输入时按下 Enter 时它会自动添加新行。
尝试使用 nl2br,它似乎不起作用。我的代码:
从上一页发布:
$BREAKINGNEWS=nl2br($_POST['BREAKINGNEWS']);
获取该信息并将其放入电子邮件的消息中:
$message .= nl2br($BREAKINGNEWS);
如您所见,我已将其放入两次,但它仍然不起作用并在每行末尾打印出 \r\n 。
我尝试只在 POST 和 $message 上执行此操作,但它不起作用。
有什么想法吗?
I'm trying to post some information from the previous page, and then email it out.
The info that is posted from the previous page is inside a text area, and I want it to automatically add new lines when the user has pressed enter when typing in that text area.
Tried using nl2br, it doesn't seem to work. My code:
Posting from previous page:
$BREAKINGNEWS=nl2br($_POST['BREAKINGNEWS']);
Taking that info and putting it into the email's message:
$message .= nl2br($BREAKINGNEWS);
As you can see I have put it twice, but it still doesn't work and prints out \r\n at the end of each line.
I've tried doing it just on the POST and just on the $message but it refuses to work.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能正在使用 SQL 转义,仅当输出将在 SQL 查询中使用时才应应用 SQL 转义。使用
nl2br()
时尽量不要转义数据。You might be using SQL escaping, You should only apply SQL escaping when the output is going to be used in a SQL query. Try to not escape the data when you use
nl2br()
.将“\r\n”替换为“\n”?
编辑:
您是否在 PHPMailer 中设置
IsHTML(true)
?Replace "\r\n" with "\n"?
EDIT:
Are you setting
IsHTML(true)
in PHPMailer?请尝试这个:
Please try this: