按提交时联系表格转到空白页面

时间:2017-01-26 02:56:10

标签: php html forms twitter-bootstrap contact-form

我有一个发送电子邮件的联系表单,但是当我按提交时,它会转到一个空白页面,如果反垃圾邮件问题没有填写,则不会显示感谢信息或任何错误消息进行。

我试过回复消息等但没有用!

我对PHP很新,所以也许我错过了什么?我正在使用bootstrap框架

以下是联系表单PHP代码(位于联系页面顶部):

<?php
$name = ($_POST['name']);
$email = ($_POST['email']);
$message = ($_POST['message']);
$from = 'Contact Form'; 
$to = 'bob@bobswebsite.co.uk'; 
$subject = "Enquiry from Visitor " . $name;
$human = ($_POST['human']);

$body = "From: $name\n E-Mail: $email\n Message:\n $message";

if (($_POST['submit']) && $human == '4') {               
    if (mail ($to, $subject, $body, $from)) { 
    echo '<p>Your message has been sent!</p>';
} else { 
    echo '<p>Something went wrong, go back and try again!</p>'; 
} 
} else if (($_POST['submit']) && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>

这是联系表格html:

 <form method="post" action="contact.php" method="POST" enctype="multipart/form-data">
 <div class="form-group">
  <label class="control-label " for="name">
   <p>Name</p>
  </label>
  <input class="form-control" id="name" name="name" type="text"/>
 </div>



 <div class="form-group ">
  <label class="control-label requiredField" for="email">
   Email
   <span class="asteriskField">
    *
   </span>
  </label>
  <input class="form-control" id="email" name="email" type="text"/>
 </div>

 <div class="form-group">
    <label class="control-label requiredField" for="contact-subject">Subject</label>
    <input type="text" name="subject" class="contact-subject form-control" id="contact-subject">
</div>



 <div class="form-group">
  <label class="control-label " for="message">
   Message
  </label>
  <textarea class="form-control" cols="40" id="message" name="message" rows="10"></textarea>
 </div>
 <div class="form-group">

  <label>*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here">
   <button class="btn btn-success" name="submit" type="submit" value="submit">
    Submit
   </button>


 </div>
</form>

任何帮助将不胜感激!我一直在网上搜索无穷无尽的答案,但我在这里或其他地方找到的任何东西都不适合我

0 个答案:

没有答案