0

嗨,我制作了一个由 PHP 生成的非常简单的 HTML 电子邮件。这是由我网站上的联系表格提供的。我的问题是,在我为用户消息使用文本区域框的地方,这不会将回车符带到 PHP 字符串中。无论如何我可以允许这样做吗?因为当我通过它收到电子邮件时,它看起来被压扁了。谢谢。

更新:

我的代码:

if(count($_GET)){
$name = $_GET["name"];
$company = $_GET["company"];
$mail_from = $_GET["email"]; 
$phone = $_GET["phone"]; 
$address = $_GET["address"]; 
$postcode = $_GET["postc"]; 
$subject = $_GET["subject"]; 
$message = nl2br($_GET["comment"]);
$headers = "From: " . strip_tags($_GET['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_GET['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";}

然后验证字符串

if ($valid = true){
$finalmessage = '<html><body>';
$finalmessage .= '<p>From: '.$name.'</p>';
$finalmessage .= '<p>Company: '.$company.'</p>';
$finalmessage .= '<p>Email: '.$mail_from.'</p>';
$finalmessage .= '<p>Phone: '.$phone.'</p>';
$finalmessage .= '<p>Address: '.$address.'</p>';
$finalmessage .= '<p>Postcode: '.$postcode.'</p>';
$finalmessage .= '<p>Message:<br /> '.$message.'</p>';
$finalmessage .= '</body></html>';

$to ='myemail@myemail.co.uk';
$send_contact=mail($to,$subject,$finalmessage,$headers);}

这仍然不起作用。一切正常,但如果用户在文本区域中使用回车,这不会被传递,实际的消息会被整理。

4

2 回答 2

0

换行符 (\r,\n) 不会在 html 中换行。你试过 nl2br($userinputtext) 吗?

于 2013-10-21T12:10:47.540 回答
0

你必须使用nl2br($text);..

于 2013-10-21T12:09:46.237 回答