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

发布于 2024-11-30 18:44:43 字数 4235 浏览 2 评论 0原文

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

看看我是如何输入的:

在此处输入图像描述

然后在发送给我的电子邮件 (HTML) 中,一切都合而为一line:

在此处输入图像描述

如您所见,所有内容都在一行中。我怎样才能让它不在这一行?

这是我的代码:

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

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

I have a contact form script and when the user submits it, they get an email and I get one. But there's a problem with the "message" textarea in the HTML email. It puts it all in one line.

See how I type it out:

enter image description here

And then in the email sent to me (HTML) its all in one line:

enter image description here

As you can see it is all in one line. How can I get it to not be in this line?

This is my code:

<?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;
    }
?>

Note: $emailContent is the email that goes to me and $emailContents is the email that goes to the user.

I tried using the str_replace() and that just caused parsing problems and I could not get that to work. I'm sure I wasn't using it right.

Can someone help me with this? Any help is highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱要勇敢去追 2024-12-07 18:44:43

使用 nl2br();

因此,将此代码段编辑

Message: 

".$message."

Message: 

".nl2br($message)."

use nl2br();

So edit this snippet

Message: 

".$message."

to

Message: 

".nl2br($message)."
眼眸 2024-12-07 18:44:43

您可以在 $messagenl2br() 函数> 将换行符更改为
标记。

You can use nl2br() function on $message to change newlines into <br /> tags.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文