<?php
$error = "";
//print_r($_POST);die;
if (!isset($_POST['name']) || $_POST['name'] == "") {
    $error .= "\nName is required";
} else {
    if (!preg_match('/^[a-zA-Z\\s]*$/', $_POST['name'])) {
        $error .= "\nEnter valid Name";
    }
}

if (!isset($_POST['phone']) || $_POST['phone'] == "" || trim($_POST['phone']) == "") {
    $error .= " \n Phone Number is required";
}



if (!isset($_POST['service']) || $_POST['service'] == "" || trim($_POST['service']) == "") {
    $error .= " \nService is required";
}


if (!isset($_POST['vname']) || $_POST['vname'] == "" || trim($_POST['vname']) == "") {
    $error .= " \nVname is required";
}

if (!isset($_POST['vnumber']) || $_POST['vnumber'] == "" || trim($_POST['vnumber']) == "") {
    $error .= " \nVnumber is required";
}

if (!isset($_POST['date']) || $_POST['date'] == "" || trim($_POST['date']) == "") {
    $error .= " \nDate is required";
}

if (!isset($_POST['address']) || $_POST['address'] == "" || trim($_POST['address']) == "") {
    $error .= " \nAddress is required";
}


if (!isset($_POST['message']) || $_POST['message'] == "" || trim($_POST['message']) == "") {
    $error .= " \nMessage is required";
}

if ($error == "") {

    require 'PHPMailer/PHPMailerAutoload.php';
    $mail = new PHPMailer;
    $message_body = "<html><body><table border=5px>";
    $message_body .= "<tr><td colspan='2' style='color : #C50B33; font-size : 20px; '><b>Request For Contact</b></td></tr>";
    $message_body .= "<tr><td>Contact's Full Name : </td><td>" . $_POST['name'] . "</td></tr>";
     $message_body .= "<tr><td>Contact's Phone : </td><td>" . $_POST['phone'] . "</td></tr>";
    $message_body .= "<tr><td>Contact's Service : </td><td>" . $_POST['doctor'] . "</td></tr>";
     $message_body .= "<tr><td>Contact's Vehicle Name : </td><td>" . $_POST['doctor'] . "</td></tr>";
      $message_body .= "<tr><td>Contact's Vehicle Number : </td><td>" . $_POST['doctor'] . "</td></tr>";
       $message_body .= "<tr><td>Contact's Date : </td><td>" . $_POST['doctor'] . "</td></tr>";
    $message_body .= "<tr><td>Contact's Address : </td><td>" . $_POST['message'] . "</td></tr>";
     $message_body .= "<tr><td>Contact's Message : </td><td>" . $_POST['message'] . "</td></tr>";


    $message_body .= "</table></body></html>";
   
    $mail->addAddress('getautotherapy@gmail.com');
    $mail->AddBcc('backupilogicx@gmail.com');

    $mail->Subject  = 'Contact Us Form';
    $mail->isHTML(true);
    $mail->Body = $message_body;

    if (!$mail->send()) {
        echo "Sorry, an error occurred while sending your mail. Please send again..!";
    } else {
        //echo "sent";
         echo "<p style='color: green;'>Thank you for contacting us! We will contact you soon.</p>";
        $mail->ClearAllRecipients();
        //$mail->addAddress($_POST['email']);  // Use lowercase 'email'
        $message_body = "Thank You....We Will Get Back To You Soon..";
        $mail->Subject  = 'Contact Us Form';
        $mail->Body = $message_body;
        $mail->send();
    }
} else {
    echo $error;
}
?>
