I want to ask you for a help. I'm using simple time slot booking calendar, everything is working fine (details are transfered correctly in to msql database), but i can't send all form details to my email and also customer e-mail for a confirmation purpose.
I can only send ex. address info or name info but can't send both and also i can't send all details. Can you please help me. Thank you so much for any help from any of you guys!
book_slots.php:
<?php
include('php/connect.php');
include('new.php');
if(isset($_POST['slots_booked'])) $slots_booked = mysqli_real_escape_string($link, $_POST['slots_booked']);
if(isset($_POST['name'])) $name = mysqli_real_escape_string($link, $_POST['name']);
if(isset($_POST['address'])) $address = mysqli_real_escape_string($link, $_POST['address']);
if(isset($_POST['email'])) $email = mysqli_real_escape_string($link, $_POST['email']);
if(isset($_POST['phone'])) $phone = mysqli_real_escape_string($link, $_POST['phone']);
if(isset($_POST['booking_date'])) $booking_date = mysqli_real_escape_string($link, $_POST['booking_date']);
if(isset($_POST['cost_per_slot'])) $cost_per_slot = mysqli_real_escape_string($link, $_POST['cost_per_slot']);
$booking_array = array(
"slots_booked" => $slots_booked,
"booking_date" => $booking_date,
"cost_per_slot" => number_format($cost_per_slot, 2),
"name" => $name,
"address" => $address,
"email" => $email,
"phone" => $phone
);
$explode = explode('|', $slots_booked);
foreach($explode as $slot) {
if(strlen($slot) > 0) {
$query = "INSERT INTO bookings (date, start, name, address, email, phone) VALUES ('$booking_date', '$slot', '$name', '$address', '$email', '$phone')";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
} // Close if
} // Close foreach
header( 'Location: thankyou.php' );
?>
connect.php:
<?php
// Make a MySQL Connection
$host="my host";
$user="db_xxx";
$password="mypasswoe";
$db = "db_xxx";
$link = mysqli_connect($host, $user, $password);
mysqli_select_db($link, $db) or die(mysql_error());
?>
new.php:
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "booking@mydomain.com";
$email = $_REQUEST['email'];
$subject = "Booking Confirmation";
$comment = "Hi,
Thank you for joining
Regards Site Admin
";
//send email
mail($email, "$subject", "$comment", "From:" . $admin_email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
<form method="post">
Email: <input name="email" type="text" /><br />
Subject: <input name="subject" type="text" /><br />
Message:Your Reservation has been made. Please check reservation detail below:<br />
<textarea name="comment" rows="15" cols="40"></textarea><br />
<textarea name="name" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" />
</form>
<?php
}
?>
if(isset($_POST) ){
//form validation vars
$formok = true;
$errors = array();
//sumbission data
$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H:i:s');
//form data
$name = $_POST['name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$enquiry = $_POST['enquiry'];
$message = $_POST['message'];
//validate form data
//validate name is not empty
if(empty($name)){
$formok = false;
$errors[] = "You have not entered a name";
}
//validate email address is not empty
if(empty($email)){
$formok = false;
$errors[] = "You have not entered an email address";
//validate email address is valid
}elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$formok = false;
$errors[] = "You have not entered a valid email address";
}
//validate message is not empty
if(empty($message)){
$formok = false;
$errors[] = "You have not entered a message";
}
//validate message is greater than 20 charcters
elseif(strlen($message) < 20){
$formok = false;
$errors[] = "Your message must be greater than 20 characters";
}
//send email if all is ok
if($formok){
$headers = "MIME-Version: 1.0"."
";
$headers .= "Content-type:text/html;charset=UTF-8"."
";
$headers .= "From: ".$email."(".$enquiry.")
";
$emailbody = "<p>You have recieved a new message from the enquiries form on your website.</p>";
$emailbody .="<p><strong>Name: </strong>".$name."</p>";
$emailbody .= "<p><strong>Email Address:</strong>".$email."</p>";
$emailbody .= "<p><strong>Telephone:</strong>".$telephone."</p>";
$emailbody .= "<p><strong>Enquiry:</strong>".$enquiry."</p>";
$emailbody .="<p><strong>Message:</strong>".$message."</p>";
$emailbody .= "This message was sent from the IP Address:".$ipaddress." on ".$date." at ".$time."</p>";
mail("service@globalsx.com","New Enquiry",$emailbody,$headers);
}
//what we need to return back to our form
$returndata = array(
'posted_form_data' => array(
'name' => $name,
'email' => $email,
'telephone' => $telephone,
'enquiry' => $enquiry,
'message' => $message
),
'form_ok' => $formok,
'errors' => $errors
);
//if this is not an ajax request
if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest'){
//set session variables
session_start();
$_SESSION['cf_returndata'] = $returndata;
//redirect back to form
header('location: ' . $_SERVER['HTTP_REFERER']);
}
}