Server : LiteSpeed System : Linux us-phx-web1202.main-hosting.eu 4.18.0-553.84.1.lve.el8.x86_64 #1 SMP Tue Nov 25 18:33:03 UTC 2025 x86_64 User : u615232177 ( 615232177) PHP Version : 8.1.33 Disable Function : NONE Directory : /home/u615232177/domains/ellexsleevesapartments.com/public_html/ |
<?php use PHPMailer\PHPMailer\PHPMailer;use PHPMailer\PHPMailer\Exception;use PHPMailer\PHPMailer\SMTP;
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.php';
header('Content-Type: application/json');
$msg = '';
$errors = 0;
include("minks.php");
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get POST data
$first_name = $_POST['first_name'] ?? '';
$last_name = $_POST['last_name'] ?? '';
$email = $_POST['email'] ?? '';
$phone = $_POST['phone'] ?? '';
$check_in = $_POST['check_in'] ?? '';
$check_out = $_POST['check_out'] ?? '';
$room_type = $_POST['room_type'] ?? '';
$name = "$first_name $last_name";
$date = date('Y-m-d H:i:s');
$status = "Pending";
$remarks = "";
$stmt1 = $con -> prepare('SELECT price FROM rooms WHERE id=?');
$stmt1 -> bind_param('i',$room_type);
$stmt1 -> execute();
$stmt1 -> store_result();
$stmt1 -> bind_result($amount);
$numrows1 = $stmt1 -> num_rows();
if($numrows1 > 0){
while ($stmt1 -> fetch()) { }
}
//database start
$db_id=0;
$reservation_id = substr(md5(rand()), 0, 20);
$stmt = $con -> prepare('INSERT INTO reservations VALUES (?,?,?,?,?,?,?,?,?,?,?,?)');
$stmt -> bind_param('isssssssssss', $db_id, $reservation_id, $name, $email, $phone, $room_type, $check_in, $check_out, $date, $status, $amount, $remarks);
$stmt -> execute();
//database end
// Basic validation (optional)
if (empty($first_name) || empty($email)) {
echo json_encode(['message' => 'Missing required fields.']);
exit;
}
$subject = "$first_name $last_name - Reservation Request";
$message1 = "
<strong>First Name:</strong> $first_name<br>
<strong>Last Name:</strong> $last_name<br>
<strong>Email:</strong> $email<br>
<strong>Phone:</strong> $phone<br>
<strong>Check in:</strong> $check_in<br>
<strong>Check out:</strong> $check_out<br>
";
// Init PHPMailer
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "smtp.hostinger.com"; // sets the SMTP server
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Set encryption to STARTTLS
$mail->Port = 587; // Use port 587 for TLS
$mail->Username = "$no_reply_email"; // SMTP account username
$mail->Password = "$no_reply_password"; // SMTP account password
$mail->SetFrom("$no_reply_email", "$company_name");
$mail->addReplyTo($email, $email);
$mail->Subject = $subject;
$mail->MsgHTML("<html><body>$message1</body></html>");
$mail->addAddress("$company_email", "Reservation");
/*
$mail->clearAddresses();
$mail->clearReplyTos();
$mail->setFrom("info@ayodeleolufade.com", "Ayodele Olufade");
$mail->addAddress($email, $email);
$mail->Subject = "Your appointment request has been received";
ob_start(); // start output buffering
include("email_header.php");
$emailHeader = ob_get_clean();
ob_start();
include("email_footer.php");
$emailFooter = ob_get_clean();
$autoresponse = $emailHeader;
$autoresponse .= "
Dear $first_name,<br><br>
Thank you for booking a call with me. I will get back to you shortly to confirm the details.<br><br>
Best regards,<br>
Ayodele Olufade<br>
";
$autoresponse .= $emailFooter;
$mail->MsgHTML("<html><body>$autoresponse</body></html>");
*/
if (!$mail->send()) {
echo json_encode(['message' => 'Your reservation request has been received']);
exit();
} else {
echo json_encode(['message' => 'Your booking has been received, thank you!']);
exit();
}
} else {
echo json_encode(['message' => 'Invalid request.']);
exit();
}