<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-11259148201"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'AW-11259148201');
</script>

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

if (isset($_POST['submit'])) {
    $tripType = $_POST['tripType'];
    $from_ap1 = substr($_POST['from_ap1'], 0, 255); // Trim to maximum length of 255 characters
    $to_ap1 = substr($_POST['to_ap1'], 0, 255); // Trim to maximum length of 255 characters
    $date_ap1 = $_POST['date_ap1'];
    $date_ap2 = $_POST['date_ap2'];
    $psngr = $_POST['psngr'];
    $clas = $_POST['clas'];
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $email = isset($_POST['email']) ? $_POST['email'] : '';

    $message12 = "
    <center>
    <table style='width:464px;border-collapse: collapse;' border='1'>
    <tr style='background-color:#464141;color:#fff;text-align:center;'><td colspan='3' style='font-size: 22px;'>Book Now</td></tr>
    <tr><td style='padding: 5px 5px 5px 5px;'>Trip Type</td><td style='padding: 5px 5px 5px 5px;'>$tripType</td></tr>
    <tr><td style='padding: 5px 5px 5px 5px;'>Name</td><td style='padding: 5px 5px 5px 5px;'>$name</td></tr>
    <tr><td style='padding: 5px 5px 5px 5px;'>Phone</td><td style='padding: 5px 5px 5px 5px;'>$phone</td></tr>
    <tr><td style='padding: 5px 5px 5px 5px;'>Flying From</td><td style='padding: 5px 5px 5px 5px;'>$from_ap1</td></tr>
    <tr><td style='padding: 5px 5px 5px 5px;'>Flying to</td><td style='padding: 5px 5px 5px 5px;'>$to_ap1</td></tr>
    <tr><td style='padding: 5px 5px 5px 5px;'>Depart</td><td style='padding: 5px 5px 5px 5px;'>$date_ap1</td></tr>
    <tr><td style='padding: 5px 5px 5px 5px;'>Return</td><td style='padding: 5px 5px 5px 5px;'>$date_ap2</td></tr>
    <tr><td style='padding: 5px 5px 5px 5px;'>Passenger</td><td style='padding: 5px 5px 5px 5px;'>$psngr</td></tr>
    <tr><td style='padding: 5px 5px 5px 5px;'>Class</td><td style='padding: 5px 5px 5px 5px;'>$clas</td></tr>";

    $email_to = "sumit.sonofgod@gmail.com";
    $email_subject = "Email for: " . $name;
    $email_to_bcc = "sumit.sonofgod@gmail.com";

    $headers = 'From: ' . $email_to . "\r\n" .
               'BCC: ' . $email_to_bcc . "\r\n" .
               'X-Mailer: PHP/' . phpversion() . "\r\n" .
               "MIME-Version: 1.0\r\n" .
               "Content-Type: text/html; charset=utf-8\r\n" .
               "Content-Transfer-Encoding: 8bit\r\n\r\n";

    if (mail($email_to, $email_subject, $message12, $headers)) {
        // Email sent successfully
    } else {
        echo "Error, Message didn't send! Something's Wrong.";
    }

    // Database details
    $host = "localhost";
    $username = "playtimeparadise_sumit";
    $password = "playtimeparadise_sumit";
    $dbname = "playtimeparadise_sumit";

    // Create connection
    $con = mysqli_connect($host, $username, $password, $dbname);

    // Check connection
    if (!$con) {
        die("Connection failed: " . mysqli_connect_error());
    }

    // Insert form entries into database
    $sql = "INSERT INTO newemail (tripType, from_ap1, to_ap1, date_ap1, date_ap2, psngr, clas, name, phone) VALUES ('$tripType', '$from_ap1', '$to_ap1', '$date_ap1', '$date_ap2', '$psngr', '$clas', '$name', '$phone')";

    // Execute query and check result
    $rs = mysqli_query($con, $sql);
    if ($rs) {
        echo "<iframe style='border: none;' src='thanku.html' width='100%' height='1200px'></iframe>";
    } else {
        echo "Error, Message didn't send! Something's Wrong.";
    }

    // Close connection
    mysqli_close($con);
}
?>
