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

时间:2013-06-12 23:52:55

标签: php html css forms contact

我绝不是网页设计师/编码员,但我有足够的一般知识来让我的网站继续前进。只是一个简单的投资组合网站。

我的联系表格有些问题。它严格来说是CSS,HTML和PHP,但是当我输入信息(名称,电子邮件和消息)进行测试时,它会向我发送一封包含这些字段标题的电子邮件,但没有内容。例如,电子邮件显示为;

名称: 电子邮件: 消息:

即使填写了信息。

我感觉这是一个小事和一个愚蠢的错误,所以任何帮助都非常感谢!

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

$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\">";
}
?>

2 个答案:

答案 0 :(得分:5)

您的表单字段在一个表单中,而提交按钮在另一个表单中。它们需要与相同的形式。

<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>

答案 1 :(得分:0)

$Name = Trim(stripslashes($_POST['Name'])); 

没有

Trim

功能,应修剪(小写)。