我绝不是网页设计师/编码员,但我有足够的常识来让我的网站正常运行。只是一个简单的投资组合网站。
不过我的联系表有一些问题。它严格是 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 = "[email protected]";
$EmailTo = "[email protected]";
$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\">";
}
?>
您的表单字段位于一个表单中,提交按钮位于另一个表单中。它们需要采用相同的形式。
<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
(小写)。