isSMTP(); $userMail->Host = 'smtp.gmail.com'; $userMail->SMTPAuth = true; $userMail->Username = $sending_email; $userMail->Password = $app_password; $userMail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $userMail->Port = 587; // User Email Configuration $userMail->setFrom($sending_email, $support_name); $userMail->addAddress($user_email); $userMail->isHTML(true); $userMail->Subject = "Thank you for contacting ". $support_name; // Embed logo $userMail->addEmbeddedImage('img/logo/logo-trans.png', 'logo_cid'); // User Email Template (Responsive & clean design) $userMail->Body = << Booking Confirmation
Company Logo

Booking Confirmation

Dear {$name},

Thank you for reaching out to $support_name. We have received your booking request. Below are your booking details:

Booking Details

Car Name: {$car_name}

Drop-off Location: {$location}

Pickup Date: {$pickup_date}

Drop-off Date: {$dropoff_date}

Our team will contact you shortly to confirm your booking and provide further details.

If you have any questions, please reply to this email.

Best regards,
$support_name Team

If you didn't initiate this booking, please ignore this email. This may have been sent in error.

HTML; /*** Admin Notification Email ***/ $adminMail = new PHPMailer(true); // SMTP Configuration $adminMail->isSMTP(); $adminMail->Host = 'smtp.gmail.com'; $adminMail->SMTPAuth = true; $adminMail->Username = $sending_email; $adminMail->Password = $app_password; $adminMail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $adminMail->Port = 587; $adminMail->setFrom($sending_email, $support_name); $adminMail->addAddress($company_email); $adminMail->addReplyTo($user_email, $name); $adminMail->isHTML(true); $adminMail->Subject = "New Booking Request: {$subject}"; // Embed logo for admin email $adminMail->addEmbeddedImage('img/logo/logo-trans.png', 'logo_cid'); $currentDateTime = date('Y-m-d H:i:s'); // Admin Email Template (all details nicely presented) $adminMail->Body = << New Booking Request
Company Logo

New Booking Request Received

Booking Information

Full Name: {$name}

Email: {$user_email}

Phone Number: {$phone}

Car Name: {$car_name}

Drop-off Location: {$location}

Pickup Date: {$pickup_date}

Drop-off Date: {$dropoff_date}

Subject: {$subject}

Reply to {$name}
HTML; // Send the emails $userMail->send(); $adminMail->send(); // Redirect back to the referring page with a success status $redirectUrl = buildRedirectUrl('success'); header("Location: $redirectUrl"); exit(); } catch (Exception $e) { // On error, encode the message and redirect back with the error status $errorMessage = "&message=" . urlencode($e->getMessage()); $redirectUrl = buildRedirectUrl('error', $errorMessage); header("Location: $redirectUrl"); exit(); } } else { // Missing fields: redirect back with missing_fields status $redirectUrl = buildRedirectUrl('missing_fields'); header("Location: $redirectUrl"); exit(); } } // Include header after potential redirects // include('header.php'); // Handle status messages (this part is optional if you want to display messages on the referring page) if (isset($_GET['status'])) { switch ($_GET['status']) { case 'success': echo "

✅ Your message has been sent successfully!

"; break; case 'error': $error = isset($_GET['message']) ? htmlspecialchars($_GET['message']) : "There was an error sending your message. Please try again."; echo "

❌ $error

"; break; case 'missing_fields': echo "

⚠️ Please fill in all the required fields.

"; break; } } ?>