简体   繁体   English

HTML / CSS / PHP联系人表单正在发送空白字段

[英]HTML/CSS/PHP contact form is sending blank fields

I'm by no means a web designer/coder, but I have enough general knowledge to get my website going. 我绝对不是网页设计师/编码员,但我有足够的常识来使我的网站正常运行。 Just a simple portfolio website. 只是一个简单的投资组合网站。

I'm having some problems with my contact form though. 我的联系表格有一些问题。 It's strictly CSS, HTML and PHP but when I put in the information (name, email and message) to test it, it sends me an email with those field headings, but no content. 严格来说,它是CSS,HTML和PHP,但是当我输入信息(名称,电子邮件和消息)进行测试时,它会向我发送包含这些字段标题但没有内容的电子邮件。 For example, the email displays as; 例如,电子邮件显示为;

Name: Email: Message: 姓名:电子邮件:消息:

Even when filled out with information. 即使充满信息。

I have a feeling it's something small and a stupid error, so any help is greatly appreciated! 我感觉这是一个很小的错误,并且是一个愚蠢的错误,因此非常感谢您的帮助!

HTML 的HTML

<div id="contact-area">
<form method="post" action="contactengine.php">
<input type="text" name="Name" id="Name" placeholder="Name"/>
<input type="text" name="Email" id="Email" placeholder="Email"/>
</form>
</div>
<div id="contact-area2">
<form method="post" action="contactengine.php">
<textarea name="Message" placeholder="Message" rows="20" cols="20" id="Message"></textarea>
</form>
<div id="submit-button">
<form method="post" action="contactengine.php">
<input type="submit" name="submit" value="SUBMIT" class="submit-button" />
</form>
</div>
</div>

PHP 的PHP

<?php

$EmailFrom = "contact@brettlair.ca";
$EmailTo = "contact@brettlair.ca";
$Subject = "Contact Form";
$Name = Trim(stripslashes($_POST['Name'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 

// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.htm\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.htm\">";
}
?>

You have your form fields in one form, and the submit button in another. 您在一种表单中有表单字段,在另一种表单中有提交按钮。 They need to be in the same form. 它们必须采用相同的形式。

<form method="post" action="contactengine.php">
<input type="text" name="Name" id="Name" placeholder="Name"/>
<input type="text" name="Email" id="Email" placeholder="Email"/>

</div>
<div id="contact-area2">

<textarea name="Message" placeholder="Message" rows="20" cols="20" id="Message"></textarea>

<div id="submit-button">

<input type="submit" name="submit" value="SUBMIT" class="submit-button" />
</form>
$Name = Trim(stripslashes($_POST['Name'])); 

没有Trim功能,应trim (小写)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM