2011-08-21 49 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