基本联系表格需要指导?

时间:2014-06-17 15:14:26

标签: php html contact-form

我对网页设计完全陌生,并且因创建联系表单而陷入困境。 FWIW原创'框架'该网站来自我下载的模板。

这就是我的表单在index.html方面的样子:

<div class="col-sm-6 col-md-6">
   <form action="contact.php" method="post">

   <div class="form-group">
   <!--<label for="name">name</label>-->
   <input type="text" id="name" class="form-control" placeholder="Name" />
   </div>

   <div class="form-group">
   <!--<label for="email">email</label>-->
   <input type="text" id="email" class="form-control" placeholder="Email Address" />
   </div>

   <div class="form-group">
   <!--<label for="message">message</label>-->
   <textarea id="message" class="form-control" rows="7" placeholder="Write a message"> 
   </textarea>
   </div>
   <button type="submit" class="btn btn-primary">Send</button>

这就是contact.php的样子:

 <?php

 $name = $_POST['name'];
 $email = $_POST['email'];
 $message = $_POST['message'];

 $to = "exampleemail@gmail.com";
 $subject = "New Contact Us Enquiry";
 $text = "A visitor of ninadaviesopticians.co.uk has submitted the following enquiry.\n\nName:$name\n\nEmail: $email\n\nMessage: $message\n\nPlease respond to this enquiry within 24 hours";

 mail ($to, $subject, $text);
 header("Location:index.html");

 ?>

当我填写联系表格时,它会将电子邮件发送到所需的地址,然后向我发送“访问者”。没有问题的文字。然而,它留下了“姓名”,“电子邮件”和“电子邮件”。和&#39;消息&#39;字段为空,就好像用户从未输入过一样。

有什么想法吗?提前感谢帮助。

2 个答案:

答案 0 :(得分:3)

您的字段需要&#34; name&#34;要填写的属性要在POST或GET数据中发送,而不是ID。

例如,你的名字字段是:

<input type="text" name="name" class="form-control" placeholder="Name" />

虽然id不用于发布数据,但您可以同时拥有ID和名称。

参考:http://www.php.net//manual/en/reserved.variables.post.php

答案 1 :(得分:0)

要通过表单发布数据,字段需要具有name属性:

<input type="text" id="name" name="name" class="form-control" placeholder="Name" />

该ID仅对客户端工具非常有用。

相关问题