php - 联系表格问题,PHP/css

标签 php html css

我正在尝试实现一个简单而有效的联系表。该页面的 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>

最佳答案

嗨,你为什么要使用这行代码?

<form  action="mail.php" method="POST" enctype="multipart/form-data">

你只发送数据,没有要发送的文件图像,最好使用这个

<form  action="mail.php" method="POST">

删除加密类型。仅当有图像或文件时才使用 enctype ... 使用正确的标签

关于php - 联系表格问题,PHP/css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19556202/

相关文章:

css - IE 在每行末尾渲染尾随空白

CSS流体图像替换?

javascript - WordPress : Change name in my button from 'LOGOUT' to the name of the user?

php - 如何获取动态添加的 html 按钮上的事件

javascript - 如何将 HTML 文件的内容导入到 <div> 中而不像对象一样?

javascript - 如何从数组中检索并显示本地存储中的数据?

php - Codeigniter - 多个文件上传 -> 插入数据库 - 有问题!

php - Apache:反向代理以处理来自另一台服务器的 PHP

html - 以类 X 定位除第一个元素以外的所有元素,其中父元素在开头有另一个没有类 X 的元素

html - 如何使用 css 选择器选择表格中第一行的表格标题?