0

我在这里多次看到这个问题,大多数答案都是一样的:使用 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);
}

此时,将生成一封没有换行符的电子邮件。怎么了?

4

1 回答 1

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);
}
于 2014-01-20T12:34:49.867 回答