PHP:如何将电子邮件输出到段落中?

时间:2014-04-03 15:49:18

标签: php html

如何让我的联系表单以段落而不是仅仅一个大块文本输出消息?这是用户填写表单时的外观(即使他使用回车制作段落):

enter image description here

我的process.php代码:

<?php

$recipient = "johndoe@aol.com";
$subject = "FORM SUBMISSION";

$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$replyTo = $_POST['email'];
$sender = "From: $replyTo\r\n";
$message = $_POST['message'];
$whyContact = $_POST['whyContact'];

$sender .= "MIME-Version: 1.0\n";
$sender .= "Content-type: text/html; charset=us-ascii\n";

$msgBody = "
<html>
<head>
<title>title here</title>
</head>

<style type='text/css'>

body{width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0;}
table td {border-collapse: collapse;}
table { border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; }

</style>

<body>

<table cellpadding='0' cellspacing='0' border='0' style='width:100%;border-bottom:1px solid #eee;font-size:12px;line-height:135%;font-family:'Lucida Grande','Lucida Sans Unicode', Tahoma, sans-serif'>
<tr style='background-color:#F5F5F5'>
<th style='vertical-align:top;color:#222;text-align:left;padding:7px 9px 7px 9px;border-top:1px solid #eee;'>Name:</th>
<td style='vertical-align:top;color:#333;width:60%;padding:7px 9px 7px 0;border-top:1px solid #eee;'>$firstName $lastName</td>
</tr>
<tr style='background-color:#FFFFFF'>
<th style='vertical-align:top;color:#222;text-align:left;padding:7px 9px 7px 9px;border-top:1px solid #eee;'>Email:</th>
<td style='vertical-align:top;color:#333;width:60%;padding:7px 9px 7px 0;border-top:1px solid #eee;'>$replyTo</td>
</tr>
<tr style='background-color:#F5F5F5'>
<th style='vertical-align:top;color:#222;text-align:left;padding:7px 9px 7px 9px;border-top:1px solid #eee;'>What are you contacting us about?</th>
<td style='vertical-align:top;color:#333;width:60%;padding:7px 9px 7px 0;border-top:1px solid #eee;'>$whyContact</td>
</tr>
<tr style='background-color:#FFFFFF'>
<th style='vertical-align:top;color:#222;text-align:left;padding:7px 9px 7px 9px;border-top:1px solid #eee;'>Message:</th>
<td style='vertical-align:top;color:#333;width:60%;padding:7px 9px 7px 0;border-top:1px solid #eee;'>$message</td>
</tr>
</table>
</body>
</html>
";

mail($recipient, $subject, $msgBody, $sender);
?>

1 个答案:

答案 0 :(得分:5)

也许试试

$message = nl2br($_POST['message']);

PHP新行到BR nl2br()