Current Directory: /home/aissorg/public_html
Viewing File: /home/aissorg/public_html/rooms-mail.php
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require_once('TCPDF/tcpdf.php');
include('admin/include/config.php');
session_start();
if (!isset($_SESSION['booking_id'])) {
die("Invalid access.");
}
$bookingId = $_SESSION['booking_id'];
unset($_SESSION['booking_id']);
$sql = "SELECT * FROM rooms WHERE id = ?";
$stmt = $con->prepare($sql);
$stmt->bind_param("i", $bookingId);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$stmt->close();
if (!$row) {
die("Booking not found.");
}
// 📁 Path to your LOCAL LOGO — MUST EXIST on your server
$localLogoPath = __DIR__ . '/img/logo.png';
// Check if logo exists
if (!file_exists($localLogoPath)) {
die("Logo file NOT FOUND at: <br>" . $localLogoPath);
}
// HTML content for email and PDF
$htmlContent = '
<div style="border: 2px dashed #503b3a; padding: 10px; width: 590px; font-family: Arial, sans-serif;background: radial-gradient(circle, #FFFF99 50%, #FF8C00 100%);">
<table width="100%" border="0" cellpadding="5">
<tr>
<td align="center"><img src="cid:logo_cid" alt="Sai Baba Temple Logo" width="150"></td>
</tr>
</table>
<h2 style="text-align:center;color:#80391e;">Sai Baba Temple Room Reservation Confirmation</h2>
<p>Dear <strong>' . htmlspecialchars($row['name']) . '</strong>,<br>Thank you for your room booking. Here are your reservation details:</p>
<table border="0" style="width: 100%; margin-top: 15px;">
<tr><td style="padding: 10px;"><strong>Name:</strong></td><td>' . $row['name'] . '</td></tr>
<tr><td style="padding: 10px;"><strong>Mobile:</strong></td><td>' . $row['mobile'] . '</td></tr>
<tr><td style="padding: 10px;"><strong>Email:</strong></td><td>' . $row['email'] . '</td></tr>
<tr><td style="padding: 10px;"><strong>Check-In Date:</strong></td><td>' . $row['checkin_date'] . '</td></tr>
<tr><td style="padding: 10px;"><strong>Check-Out Date:</strong></td><td>' . $row['checkout_date'] . '</td></tr>
<tr><td style="padding: 10px;"><strong>Rooms:</strong></td><td>' . $row['rooms'] . '</td></tr>
<tr><td style="padding: 10px;"><strong>Adults:</strong></td><td>' . $row['adult'] . '</td></tr>
<tr><td style="padding: 10px;"><strong>Kids:</strong></td><td>' . $row['kids'] . '</td></tr>
<tr><td style="padding: 10px;"><strong>Aadhar No:</strong></td><td>' . $row['aadhar'] . '</td></tr>
<tr><td style="padding: 10px;"><strong>Address:</strong></td><td>' . $row['address'] . ', ' . $row['city'] . ', ' . $row['state'] . ', ' . $row['country'] . ' - ' . $row['zip_code'] . '</td></tr>
<tr><td style="padding: 10px;"><strong>Purpose:</strong></td><td>' . $row['purpose'] . '</td></tr>
</table>
</div>';
// Generate PDF
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator('Sai Baba Temple');
$pdf->SetAuthor('Temple Admin');
$pdf->SetTitle('Room Booking Confirmation');
$pdf->SetMargins(15, 30, 15); // Increased top margin for logo
$pdf->AddPage();
// Center Logo Horizontally
$imgWidth = 40; // Width of your image in mm
$pageWidth = $pdf->getPageWidth();
$x = ($pageWidth - $imgWidth) / 2; // Calculate center
$y = 10; // Y position from top
$pdf->Image($localLogoPath, $x, $y, $imgWidth);
// Write HTML content below the logo
$pdf->writeHTML($htmlContent, true, false, true, false, '');
// Save PDF temporarily
$savePath = __DIR__ . '/temp_pdfs/';
if (!is_dir($savePath)) {
mkdir($savePath, 0755, true);
}
$pdfFile = $savePath . 'room_booking_' . $bookingId . '.pdf';
$pdf->Output($pdfFile, 'F'); // Save PDF
// Email Setup
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'v22437909.sin01.serveradd.com';
$mail->SMTPAuth = true;
$mail->Username = 'admin@aiss.org.in';
$mail->Password = 'Oo(hKvdR.52E';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('admin@aiss.org.in', 'Sai Baba Temple');
if (!empty($row['email']) && filter_var($row['email'], FILTER_VALIDATE_EMAIL)) {
$mail->addAddress($row['email'], $row['name']); // Customer
}
$mail->addAddress('kavintechsolutions@gmail.com'); // Internal copy
$mail->addBCC($row['email'], $row['name']);
$mail->addReplyTo($row['email'], $row['name']);
$mail->isHTML(true);
$mail->Subject = "Sai Baba Room Booking Confirmation";
$mail->Body = $htmlContent;
$mail->addAttachment($pdfFile); // Attach generated PDF
// 👇 Embed logo in email so it shows up even without internet
$mail->addEmbeddedImage($localLogoPath, 'logo_cid', 'logo.png');
$mail->send();
} catch (Exception $e) {
echo "Email could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
// Cleanup temporary files
if (file_exists($pdfFile)) {
unlink($pdfFile);
}
?>