2011-08-21 50 views
2

我有一个联系表格脚本,当用户提交它时,他们会收到一封电子邮件,我会得到一个。但是HTML电子邮件中的“message”textarea存在问题。它将所有内容放在一行中。联系表格提交脚本 - HTML电子邮件问题

看我怎么键入出来:

enter image description here

然后在发送给我(HTML)的电子邮件一切都在一个行:

enter image description here

正如你所看到的这一切都在一条线上。我怎样才能让它不在这一行?

这是我的代码:

<?php 

// load the variables form address bar 
$subject = $_POST["subject"]; 
$message = $_POST["message"]; 
$from = $_POST["from"]; 
$name = $_POST["name"]; 
$verif_box = $_POST["verif_box"]; 

// remove the backslashes that normally appear when entering " or ' 
$message = stripslashes($message); 
$subject = stripslashes($subject); 
$from = stripslashes($from); 
$name = stripslashes($name); 
$emailContent = "Hello Nathan, 

".$name." is trying to contact WeeBuild Support. Here's what they submitted: 
<br /><br /> 
<div style='background-color:#ccc;padding:10px;border:1px solid grey;'> 

Name: <strong>".$name."</strong> 
<br /><br /> 
Email: <strong>".$from."</strong> 
<br /><br /> 
Subject: <strong>".$subject."</strong> 
<br /><br /> 
Message: 
<br /><br /> 
<strong>".$message."</strong> 
<br /><br /><br /> 
Their IP Address: <strong>".$_SERVER['REMOTE_ADDR']."</strong> 

</div> 
<br /><br /> 
To email them back, simply reply to this message."; 


$emailContents = "Hello ".$name.", 

Thank you for contacting WeeBuild Support! This email is to let you know that we have received your support request and that we will reply soon. 

For your record, here is what you submitted: 

----------------------------------------------------------------------------- 

Your Name: ".$name." 

Your Email: ".$from." 

Subject: ".$subject." 

Message: 

".$message." 

----------------------------------------------------------------------------- 

In the meanwhile, make sure to add [email protected] to your contact list/safe senders list so our emails don't end up in your junk folder. 


We will be with you shortly! 

Kind regards, 
WeeBuild Support Team 
www.WeeBuild.biz"; 

$emailContent = stripslashes($emailContent); 
$emailContents = stripslashes($emailContents); 
$headers = "From: " . $from . "\r\n"; 
$headers .= "Reply-To: ". $from . "\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 


// check to see if verificaton code was correct 
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){ 
    // if verification code was correct send the message and show this page 
    mail("[email protected]", 'WeeBuild Contact Form: "'.$subject.'"', $emailContent, $headers); 
    mail($from, 'Thank you for contacting WeeBuild Support!', $emailContents, "From: [email protected]"); 
    // delete the cookie so it cannot sent again by refreshing this page 
    setcookie('tntcon',''); 
} else if(isset($message) and $message!=""){ 
    // if verification code was incorrect then return to contact page and show error 
    header("Location: index.php?name=$name&subject=$subject&from=$from&message=".urlencode($message)."&wrong_code=true"); 
    exit; 
} else { 
    echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"> 
<html><head> 
<title>Access Denied</title> 
<style type=\"text/css\"> 
body { 
font-family: Arial, sans-serif; 
} 
</style> 
</head><body> 
<h1>Access Denied</h1> 
<p>This page cannot be accessed directly. The needed variables to submit were not provided.</p> 
</body></html>"; 

    exit; 
    } 
?> 

注:$emailContent是问我和$emailContents是去给用户的电子邮件的电子邮件。

我尝试使用str_replace(),这只是导致解析问题,我无法得到它的工作。我确定我没有正确使用它。

有人可以帮助我吗?任何帮助,高度赞赏。

回答

3

使用nl2br();

所以编辑这个片段

Message: 

".$message." 

Message: 

".nl2br($message)." 
+0

哦,我明白了,谢谢! :) – Nathan

+0

是的,抱歉,我昨天忘了。我接受了! :) – Nathan

1

可以使用nl2br()功能上$message改变换行符到<br />标签。

+0

这是我的消息副本:页 – genesis