1

I'd greatly appreciate some help with my PHP contact form. I've followed a number of tutorials to try and get this working and I am still without luck. The code is as follows.

N.B. I am using styling elements defined within the Twitter Bootstrap Framework and the form appears in a modal-style popup (although I can't see why this would affect the form).

Is there anything else I might have to activate/configure on my hosting side apart from having PHP enabled.

FORM CODE:

<form method="POST" action="mail.php">
    <fieldset>
      <input type="text" name="first_name" placeholder="First Name">
      <input type="text" name="last_name" placeholder="Last Name">
      <input type="email" name="email" placeholder="Email Address">
      <div class="controls controls-row">
        <input type="date" name="check_in" placeholder="Check in Date"><span class="help-inline">Check-in</span>
      </div>
      <div class="controls controls-row">
        <input type="date" name="check_out" placeholder="Check out Date"><span class="help-inline">Check-out</span>
      </div>
      <input type="number" name="rooms" min="1" max="7" placeholder="Number of Rooms">
      <input type="number" name="occupants" min="1" max="14" placeholder="Number of Occupants">
      <textarea rows="3" name="additional" input class="input-xparge" placeholder="Additional requirements" class="span5"></textarea>
    </fieldset>

    <div class="modal-footer">
      <button type="submit" input type="submit" id="submit" class="btn btn-block btn-large btn-success"  value="submit">Submit</button>
    </div>
  </form>

PHP CODE:

<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$check_in = $POST['check_in'];
$check_out = $POST['check_out'];
$rooms = $POST['rooms'];
$occupants = $POST['occupants'];
$additional = $_POST['additional'];
$from = "From: $first_name";
$to = "[email protected]";
$subject = "New Booking Enquiry";

$body = "First Name: $first_name\n Last Name: $last_name\n Email: $email\n Check In: $check_in\n Check Out: $check_out\n Number of Rooms: $rooms\n Number of Occupants: $occupants\n Additional Information: $additional"; 

if ($_POST['submit']) {
 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>'; 
   }
}

?>

Thank you kindly in advance!

2
  • what is the error/problem you get? Commented Feb 12, 2013 at 16:53
  • You should describe what is not working. Commented Feb 12, 2013 at 16:54

1 Answer 1

3

don't you need to add name="submit" to the 'button' tag?

in your php, you are testing 'if ($_POST['submit']) {'

and $_POST['submit'] might not being getting set without name="submit" in that tag

Sign up to request clarification or add additional context in comments.

2 Comments

That should fix it. I want to add that you should filter/clean your users input. Spammers can use your script to sent spam from your server this way.
Thank you for your help! Did the trick. This community is awesome :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.