0

I have a contact form which sends emails fine, but when I press submit it goes to a blank page and doesn't display a thank you message or any error message if the anti spam question isn't filled out.

I have tried echoing the messages etc but to no use!

I am rather new to PHP so perhaps I am missing something? I am using bootstrap frameworks

Here is the contact form PHP code (at the top of the contact page):

<?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>';
}
?>

Here is the contact form 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>

Any help would be much appreciated! I have been searching endless answers online but nothing I have found on here or elsewhere works for me

ck777
  • 161
  • 1
  • 1
  • 20
  • Walk through your output. Echo out $_POST['submit'], $_POST['human'], etc. If a blank page is being displayed, the code is failing before "if (($_POST['submit']) && $human == '4') " passes. – Eoghan Jan 26 '17 at 03:01
  • Thanks for your suggestion, I have tried this but with no luck, any chance you could please show me an example of the line of code? I just cannot get the message to display - it sends an email though.. – ck777 Jan 26 '17 at 03:33

0 Answers0