<?php
if (isset($_REQUEST['sub'])) {

    $name    = $_REQUEST['name'];
    $mail    = $_REQUEST['mail'];
    $mob     = $_REQUEST['mobile'];
    $add     = $_REQUEST['address'];
    $country = $_REQUEST['country'];
    $place   = $_REQUEST['place'];
    $fleets  = $_REQUEST['fleets'];
    $pick    = !empty($_REQUEST['pick']) ? $_REQUEST['pick'] : 'NULL';
    $drop    = $_REQUEST['drop'];
    $date    = $_REQUEST['date'];
    $time    = $_REQUEST['time'];
    $adult   = $_REQUEST['adult'];
    $child   = $_REQUEST['child'];
    $radio   = $_REQUEST['radio'];

    // Normalize values
    $places = [
        "01" => "AIRPORT",
        "02" => "RAILWAY STATION",
        "03" => "OTHERS"
    ];
    $fleets_map = [
        "01" => "SEDAN CARS",
        "02" => "SUV CARS",
        "03" => "VAN'S OTHERS",
        "04" => "BUS A/C"
    ];
    $place  = $places[$place] ?? 'Unknown';
    $fleets = $fleets_map[$fleets] ?? 'Unknown';

    // Construct message
    $message = "Booking Details\n";
    $message .= "NAME: $name\n";
    $message .= "MOBILE: $mob\n";
    $message .= "EMAIL: $mail\n";
    $message .= "ADDRESS: $add\n";
    $message .= "COUNTRY: $country\n";
    $message .= "PICK UP PLACE: $place\n";
    $message .= "OTHER PLACE: $pick\n";
    $message .= "FLEETS: $fleets\n";
    $message .= "DROP AT: $drop\n";
    $message .= "DATE: $date\n";
    $message .= "TIME: $time\n";
    $message .= "ADULT: $adult\n";
    $message .= "CHILD: $child\n";
    $message .= "JOURNEY TYPE: $radio\n";

    // Headers
    $to = "pondicherrycartravels@gmail.com";
    $subject = "Taxi Booking Request from $name";
    
    // Must be domain email to avoid GoDaddy blocking it
    $fromEmail = "info@pondicherrycarrentalsandtravels.com"; // Must be your domain's email

    $headers = "From: $fromEmail\r\n";
    $headers .= "Reply-To: $mail\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/plain; charset=UTF-8\r\n";

    // Send mail
    if (mail($to, $subject, $message, $headers)) {
        echo "<script>alert('Thank you for contacting us');</script>";
    } else {
        echo "<script>alert('Failed to send email. Please try again later.');</script>";
    }
}
?>
