联系表单提交脚本 - HTML电子邮件问题

时间:2011-08-21 08:05:08

标签: html-email php

我有一个联系表单脚本,当用户提交它时,他们会收到一封电子邮件,我会收到一封。但HTML电子邮件中的“消息”textarea存在问题。它把它全部放在一行。

了解我如何输入:

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 support@weebuild.biz 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("nathan@weebuild.biz", 'WeeBuild Contact Form: "'.$subject.'"', $emailContent, $headers);
    mail($from, 'Thank you for contacting WeeBuild Support!', $emailContents, "From: support@weebuild.biz");
    // 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(),这只是导致解析问题,我无法让它工作。我确定我没有正确使用它。

有人可以帮我吗?任何帮助都非常感谢。

2 个答案:

答案 0 :(得分:3)

使用nl2br();

所以编辑此代码段

Message: 

".$message."

Message: 

".nl2br($message)."

答案 1 :(得分:1)

您可以使用$message上的nl2br()功能将换行符更改为<br />代码。

相关问题