我在这里看过很多次这个问题,大多数答案都是一样的:使用nl2br()函数。这是伟大的,就其而言...... 无论如何,首先是将内容发送为$ message的表单:
<textarea name=aMessage rows="46" cols="60" tabindex=5 value=<?php $message; ?> >
Honourable Jane Doe,
Minister of Environment
Sincerely,
</textarea>
然后转换:
$message = nl2br(htmlentities($message));
echo $message;
注意:使用nl2br()时,后面的回显显示正确插入换行符的内容。大!然后将其移交给send_mail()函数,该函数生成格式化的电子邮件(整齐的盒子等) - 看起来像:
function send_email($name,$mail,$message) {
$to = "my@email.net";
$subject = "Testing - Public Input";
$body = "
<html><head>
</head><body>Testing - Public Input<br><br>
<table>
<tr><th>Name:</th><th>Email Address:</th></tr>
<tr><td>".$name."</td><td>".$mail."</td></tr>
<tr><th>FEEDBACK:</th></tr>
<tr>
<td colspan='2' style='padding:10px;display:block'>".$message."</td>
</tr>
</table>
</body>
<html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: thor@gator4116.hostgator.com\n";
mail($to,$subject,$body,$headers);
}
此时,会生成一封没有换行符的电子邮件。有什么问题?
答案 0 :(得分:0)
试试这个:
function send_email($name,$mail,$message) {
$to = "my@email.net";
$subject = "Testing - Public Input";
$body = <<< EOF
<html><head>
</head><body>Testing - Public Input<br><br>
<table>
<tr><th>Name:</th><th>Email Address:</th></tr>
<tr><td>".$name."</td><td>".$mail."</td></tr>
<tr><th>FEEDBACK:</th></tr>
<tr>
<td colspan='2' style='padding:10px;display:block'>".$message."</td>
</tr>
</table>
</body>
<html>
EOF;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: thor@gator4116.hostgator.com\n";
mail($to,$subject,$body,$headers);
}