我正在尝试实现一个简单而有效的联系表格。该页面的 HTML 如下所示。下面也列出了我正在使用的 mail.php 表单。我想要联系表单做的是需要字段,如果用户没有填写必填字段,它会将它们发送回带有错误代码的相同表单。我想我已经接近了,但由于某种原因,它在提交表单时给了我一个错误代码,填写或为空。你可以在darthvixcustomsabers.com上看到它,而不是使用 Apache 服务器来查看。我也希望能够通过使用 textarea 在 css 中指定列/行,但这也不起作用。
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo <a href="contact.html"></a>;
}
else
{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("horgantm@gmail.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
<!doctype html>
<html>
<head>
<title> DV Custom Sabers </title>
<meta charset="utf-8">
<link type="text/css" rel="stylesheet" href="style/kotorsale.css" />
<meta name="viewport" content="width=device-width" />
</head>
<div class="header"><a href="index.html">Darthvix Custom Sabers</a></div>
<div class="header1">DV Custom Sabers is the place to go for your saber needs!</div>
<div class="logo"><a href="index.html"><img src="images/logo.png" alt="schedule" height="200" width="350" border="0"></a></div>
<ul id="nav">
<li><a href="index.html">Home</a></li>
<li><a href="aboutme.html">About Me</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="Gallery.html">Gallery</a></li>
<li><a href="kotorsale.html">For Sale</a></li>
<li><a href="buildlog.html">Build Log</a></li>
<li><a href="contact.html"> Contact Us</a></li>
</ul>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
</div>
</body>
</html>