【问题标题】:Contact form submit script - HTML email problem联系表单提交脚本 - HTML 电子邮件问题
【发布时间】:2011-08-21 08:05:08
【问题描述】:

我有一个联系表单脚本,当用户提交它时,他们会收到一封电子邮件,我也会收到一封。但是 HTML 电子邮件中的“消息”文本区域存在问题。它将所有内容放在一行中。

看看我是怎么打出来的:

然后在发送给我的电子邮件 (HTML) 中将其全部放在一行中:

如您所见,这一切都在一行中。我怎样才能让它不在这条线上?

这是我的代码:

<?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(),但这只是导致解析问题,我无法让它工作。我确定我没有正确使用它。

有人可以帮我解决这个问题吗?非常感谢任何帮助。

【问题讨论】:

    标签: html-email php


    【解决方案1】:

    使用nl2br();

    所以编辑这个 sn-p

    Message: 
    
    ".$message."
    

    Message: 
    
    ".nl2br($message)."
    

    【讨论】:

      【解决方案2】:

      您可以在$message 上使用nl2br() 函数将换行符更改为&lt;br /&gt; 标签。

      【讨论】:

      • 这是我的消息的副本:p
      猜你喜欢
      • 2016-01-26
      • 1970-01-01
      • 2018-11-05
      • 1970-01-01
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      • 2021-09-24
      相关资源
      最近更新 更多