I'm trying to make a simple submission form in my index.html file that will send an email with the values, but there is always blank value for phone number where as I get other values in email after grabbing them with $_POST. The problem is only with the phone number field. Rest all things are comming in the email.
HTML CODE:
<form class="form-inline reservation-horizontal clearfix" role="form" method="post" action="php/reservation.php" name="reservationform" id="reservationform">
<div id="message"></div><!-- Error message display -->
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<label for="email" accesskey="E">E-mail</label>
<input name="email" type="text" id="email" value="" class="form-control" placeholder="Please enter your E-mail"/>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<label for="room">Room Type</label>
<div class="popover-icon" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus."> <i class="fa fa-info-circle fa-lg"> </i> </div>
<select class="form-control" name="room" id="room">
<option selected="selected" disabled="disabled">Select a room</option>
<option value="Hotel Suite">Hotel Suite</option>
<option value="Standard Room I">Standard Room I</option>
<option value="Standard Room II">Standard Room II</option>
</select>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<label for="checkin">Check-in</label>
<div class="popover-icon" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="Check-In is from 11:00"> <i class="fa fa-info-circle fa-lg"> </i> </div>
<i class="fa fa-calendar infield"></i>
<input name="checkin" type="text" id="checkin" value="" class="form-control" placeholder="Check-in"/>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<label for="phone" >Phone No.</label>
<input name="phone" type="text" id="phone" class="form-control" placeholder="Phone No."/>
</div>
</div>
<div class="col-sm-1">
<div class="form-group">
<div class="guests-select">
<label>Guests</label>
<i class="fa fa-user infield"></i>
<div class="total form-control" id="test">1</div>
<div class="guests">
<div class="form-group adults">
<label for="adults">Adults</label>
<div class="popover-icon" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="+18 years"> <i class="fa fa-info-circle fa-lg"> </i> </div>
<select name="adults" id="adults" class="form-control">
<option value="1">1 adult</option>
<option value="2">2 adults</option>
<option value="3">3 adults</option>
</select>
</div>
<div class="form-group children">
<label for="children">Children</label>
<div class="popover-icon" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="0 till 18 years"> <i class="fa fa-info-circle fa-lg"> </i> </div>
<select name="children" id="children" class="form-control">
<option value="0">0 children</option>
<option value="1">1 child</option>
<option value="2">2 children</option>
<option value="3">3 children</option>
</select>
</div>
<button type="button" class="btn btn-default button-save btn-block">Save</button>
</div>
</div>
</div>
</div>
<div class="col-sm-2">
<button type="submit" class="btn btn-primary btn-block">Book Now</button>
</div>
</div>
</form>
PHP CODE:
<?php
if(!$_POST) exit;
// Email address verification.
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "
");
$email = $_POST['email'];
$checkin = $_POST['checkin'];
$phone = $_POST['phone'];
$room = $_POST['room'];
$adults = $_POST['adults'];
$children = $_POST['children'];
if(trim($email) == '') {
echo '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Attention! Please enter a valid email address.</div>';
exit();
} else if(trim($room) == '') {
echo '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Attention! Please enter a your room.</div>';
exit();
} else if(trim($checkin) == '') {
echo '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Attention! Please enter your check-in date.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
$address = "****@gmail.com";
$e_subject = 'A reservation request by ' . $email . '.';
$e_body = "Good news! A reservation has been requested by $email
and Phone No.: $phone
The customer wants to check-in at: $checkin
The customer requested a $room room for $adults adult(s) and $children child(ren)." . PHP_EOL . PHP_EOL;
$e_reply = "You can contact the customer via email, $email or hit 'reply' in your email browser to make the reservation complete.";
$msg = wordwrap( $e_body . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Reservation sent successfully!</h1>";
echo "<p>Thank You for your booking request. Our representatives will connect with you shortly.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
} ?>