HTML php电子邮件中的换行符 [英] linebreak in html php email
本文介绍了HTML php电子邮件中的换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码使用php通过电子邮件发送文本区域内容
I am using below code to send a textarea content as email using php
<?php
$to = $_POST['emailbox'] ;
$message1 = $_REQUEST['output_textarea'];
$subject = 'script';
$message = "
<html>
<body>
<table bgcolor='lightcyan'>
<p>heading</p>
$message1;
</table>
</body>
</html>
";
$headers = "From: admin@domain.com\r\n";
$headers .= "Reply-To: acr@domain.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject, $message, $headers);
?>
但是电子邮件忽略了文本区域中的所有换行符.如何在文本区域中保留换行符?
But the email ignoring all line breaks in the textarea. How can I keep the line break in text area ?
推荐答案
首先,这里不需要分号:
First of all, no semicolon needed here:
$message1;
当您将html用于电子邮件时,必须使用< br/>
标签来换行.
As you use html for your email message, you have to use <br/>
tags to break lines.
Best way to replace \n
with <br/>
is use of nl2br() PHP function.
在您的代码中替换:
$message1 = $_REQUEST['output_textarea'];
具有:
$message1 = nl2br($_REQUEST['output_textarea']);
这篇关于HTML php电子邮件中的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文