PHP 电子邮件:传递回车


PHP email: passing over carriage returns

嗨,我做了一个非常简单的HTML电子邮件,由PHP生成。这是由我网站上的联系表格提供的。我的问题是,当我为用户的消息使用文本区域框时,这不会将回车结果延续到 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);}

这仍然不起作用。一切正常,但是如果用户在文本区域中使用回车符,则不会传递回车符,并且实际消息会被压缩。

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

你必须

使用nl2br($text);..