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 = "lloyd.rees09@bathspa.ac.uk";
$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!

4

1 回答 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

于 2013-02-12T16:56:13.083 回答