1

我绝不是网页设计师/编码员,但我有足够的常识来让我的网站正常运行。只是一个简单的投资组合网站。

不过,我的联系表格有一些问题。它是严格的 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\">";
}
?>
4

2 回答 2

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>
于 2013-06-12T23:53:38.463 回答
0
$Name = Trim(stripslashes($_POST['Name'])); 

没有Trim函数,应该是trim(小写)。

于 2013-06-12T23:57:14.910 回答