No of visitors who read this post: 285
Type: Question
No votes yet

I’m currently in middle of developing an online reservation form for a hotel and was wondering if someone will guide to develop a good PHP mail script for reservation. Any kind of help would be appreciated.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

#

<html>
<body>
<?php
  $email = $_REQUEST['email'] ;
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  mail("someone@example.com", $subject,
  $message, "From:" . $email);
  echo "email sent";
?>
</body>
</html>

You can modify this depending on your needs but this is the basic setup for a email script.

I hope this helps.

Thank you.

# (Solution Accepted)

Hi,

In creating a reservation form, there are two things involved; A script for the form and another script for validating the form entries and posting to database if you have one.

For creating the form, you can follow the example below, name the PHP file as reservation.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="javaScript" type="text/javascript" src="calendar.js"></script>
   <link href="calendar.css" rel="stylesheet" type="text/css">
<title>Reservation Form</title>

</head>

<body>
<div class="body">
<?php
include_once 'csstyle.php';
include_once 'header.php';
?> <br />
<div class="bg">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="2"WIDTH="960"VALIGN="TOP"ALIGN="CENTER" class="bg4">
<tr valign="top"><td width="230"><form action="book.php" method="post">
<fieldset><legend class="bt">Destination Hotel</legend><br />
    Choose hotel:<br />
    <select name="hotel" id="hotel">
    <option value="Amboseli_sopa_lodge">Amboseli_sopa_lodge</option>
    <option value="Amboseli_serena_lodge">Amboseli_serena_lodge</option>
    <option value="Mada_hotel">Mada_hotel</option>
    <option value="Oltukai_lodge">Oltukai_lodge</option>
    <option value="Satao_elerai_camp">Satao_elerai_camp</option>
    <option value="Kiboslopes_cottages">Kiboslopes_cottages</option>
    <option value="Kutazama Lodge">Kutazama Lodge</option></select><br />
    </fieldset>  <br /><br />
    
    <fieldset><legend class="bt">Accommodation</legend><br />


    <table cellpadding="3"><tr valign="top"><td>
    Room type:<br /><select name="room" id="room">
            <option value="single"> single</option>
            <option value="double"> double</option>
            <option value="apartment"> apartment</option>
            </select></td><td>
    No. of Guests:<br />
    <input type="text" name="guest_no" size="3" class="bt2" />
    </td></tr></table>        
    </fieldset>                      
</td>
<td width="250">
    <fieldset><legend class="bt">Check-in</legend><br />
    <table><tr valign="top"><td>
    Date:<br />    
    <input type="text" name="check_in"><a href="#" onClick="setYears(2012, 2014);
       showCalender(this, 'check_in');">
      <img src="calender.png"></a></td></tr></table>
    </fieldset><br /><br />
    
    <fieldset><legend class="bt">Check-out</legend><br />
<table><tr valign="top"><td>
    Date:<br />    
    <input type="text" name="check_out"><a href="#" onClick="setYears(2012, 2014);
       showCalender(this, 'check_out');">
      <img src="calender.png"></a><br />
      <table id="calenderTable">
        <tbody id="calenderTableHead">
          <tr>
            <td colspan="4" align="center">
              <select onChange="showCalenderBody(createCalender(document.getElementById('selectYear').value,
               this.selectedIndex, false));" id="selectMonth">
                  <option value="0">Jan</option>
                  <option value="1">Feb</option>
                  <option value="2">Mar</option>
                  <option value="3">Apr</option>
                  <option value="4">May</option>
                  <option value="5">Jun</option>
                  <option value="6">Jul</option>
                  <option value="7">Aug</option>
                  <option value="8">Sep</option>
                  <option value="9">Oct</option>
                  <option value="10">Nov</option>
                  <option value="11">Dec</option>
              </select>
            </td>
            <td colspan="2" align="center">
                <select onChange="showCalenderBody(createCalender(this.value,
                document.getElementById('selectMonth').selectedIndex, false));" id="selectYear">
                </select>
            </td>
            <td align="center">
                <a href="#" onClick="closeCalender();"><font color="#003333" size="+1">X</font></a>
            </td>
          </tr>
       </tbody>
       <tbody id="calenderTableDays">
         <tr style="">
           <td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td>
         </tr>
       </tbody>
       <tbody id="calender"></tbody>
    </table>

     
      </td></tr></table>
    </fieldset>
    </td>
    <td width="225">
    <fieldset><legend class="bt">Personal Information</legend><br />
    Name:<br />
    <input name="name" type="text" size="30" class="bg4" />
    Surname:<br />
    <input name="surname" type="text" size="30" class="bg4" />
    Email:<br />
    <input name="email" type="text" size="30" class="bg4" />
    Phone:<br />
    <input name="phone" type="text" size="30" class="bg4" /><br />
    </fieldset> <br />           
    </td>
    <td>
    <fieldset><legend class="bt">Additional Info</legend><br />
    <textarea name="additional_info" cols="20" rows="6" class="bg4"> </textarea><br /><br />
    <input type="submit" name="submit" value="check availability" id="buttons1"/><br />
    <input type="reset" name="submit" value="Reset" id="buttons1"/>
</form>
     </fieldset>

</td></tr></TABLE>
</div>
<br />
<?php
include_once 'followus.php';
include_once 'footer.php';
?>
</div>

</body>
</html>

The validation code is as follows, name it book.php:

<div class="body">
<?php
include_once 'csstyle.php';
include_once 'header.php';
?>
<?php
/* This code will make a connection with database */
$con=mysql_connect("localhost","root","");
 
/* Now, we select the database */
mysql_select_db("youthfor_amboseli");
 
/* Now we will store the values submitted by form in variable */
$hotel=$_POST['hotel'];
$room=$_POST['room'];
$guest_no=$_POST['guest_no'];
$check_in=$_POST['check_in'];
$check_out=$_POST['check_out'];
$name=$_POST['name'];
$surname=$_POST['surname'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$additional_info=$_POST['additional_info'];

 function died($error) {
        // your error code can go here
        echo "<div class='errmsg'>Please correct the following errors.<br />";
        echo $error."<br />";
         include 'bookingform.php';
        die();
      
    }   
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email)) {
    $error_message .= 'The Email Address you entered is invalid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$name)) {
    $error_message .= 'Please enter full name.<br />';
  }    
    if(strlen($guest_no) < 1) {
    $error_message .= 'Please enter a valid Guest number.<br />';
  }
  if(strlen($phone) < 10) {
    $error_message .= 'Please enter a valid phone number.<br /></div> ';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    
 
/* Now we will write a query to insert user details into database */
$insert_bookings=mysql_query("INSERT INTO bookings ( hotel, room, guest_no, check_in, check_out, name, surname, email, phone, additional_info) VALUES ('$hotel', '$room', '$guest_no', '$check_in', '$check_out', '$name', '$surname', '$email', '$phone', '$additional_info')");

if($insert_bookings)
{
 echo "<div class='finemsg'> Reservation successful</div>";
 header('Location:thanks.php');
 }
else
{ echo "<div class='errmsg'>error in reservation</div>".mysql_error();
 include 'where.php';
 
/* closing the if else statements */
}
 
mysql_close($con);
?>
</div>

Thank you.