'error', 'text' => 'Request must come from Ajax' )); die($output); } //check $_POST vars are set, exit if any missing //Sanitize input data using PHP filter_var(). if(isset($_POST["userName"])) { if(!isset($_POST["userName"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $user_Name = filter_var($_POST["userName"], FILTER_SANITIZE_STRING); } } if(isset($_POST["firstName"]) && isset($_POST["lastName"])) { if(!isset($_POST["firstName"]) && !isset($_POST["lastName"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $user_Name = filter_var($_POST["firstName"], FILTER_SANITIZE_STRING) . " " . filter_var($_POST["lastName"], FILTER_SANITIZE_STRING); } } //education if(isset($_POST["fatherName"])) { if(!isset($_POST["fatherName"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $father_Name = filter_var($_POST["fatherName"], FILTER_SANITIZE_STRING); } } if(isset($_POST["quoteName"])) { if(!isset($_POST["quoteName"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $quote_Name = filter_var($_POST["quoteName"], FILTER_SANITIZE_STRING); } } if(isset($_POST["userAddress"])) { if(!isset($_POST["userAddress"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $user_Address = filter_var($_POST["userAddress"], FILTER_SANITIZE_STRING); } } if(isset($_POST["course"])) { if(!isset($_POST["course"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $applied_Course = filter_var($_POST["course"], FILTER_SANITIZE_STRING); } } if(isset($_POST["userEmail"])) { if(!isset($_POST["userEmail"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $user_Email = filter_var($_POST["userEmail"], FILTER_SANITIZE_EMAIL); } } if(isset($_POST["userPhone"])){ if(!isset($_POST["userPhone"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $user_Phone = $_POST["userPhone"]; } } if(isset($_POST["userSubject"])) { if(!isset($_POST["userSubject"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $user_Subject = $_POST["userSubject"]; } } if(isset($_POST["userCity"])) { if(!isset($_POST["userCity"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $user_City = $_POST["userCity"]; } } if(isset($_POST["projectType"])) { if(!isset($_POST["projectType"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $pro_type = $_POST["projectType"]; } } //Directory listing if(isset($_POST["propertyId"])) { if(!isset($_POST["propertyId"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $property_id = $_POST["propertyId"]; } } if(isset($_POST["propertyType"])) { if(!isset($_POST["propertyType"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $property_type = $_POST["propertyType"]; } } if(isset($_POST["quoteBudget"])) { if(!isset($_POST["quoteBudget"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $budget = $_POST["quoteBudget"]; } } //consultant template if(isset($_POST["service"])) { if(!isset($_POST["service"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $service = $_POST["service"]; } } //Reservation template if(isset($_POST["reservationDate"])) { if(!isset($_POST["reservationDate"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $res_date = $_POST["reservationDate"]; } } if(isset($_POST["totalPeople"])) { if(!isset($_POST["totalPeople"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $total_people = $_POST["totalPeople"]; } } //spa if(isset($_POST["reserveTime"])) { if(!isset($_POST["reserveTime"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $res_time = $_POST["reserveTime"]; } } //medical if(isset($_POST["userGender"])) { if(!isset($_POST["userGender"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $user_gender = $_POST["userGender"]; } } if(isset($_POST["userMessage"])) { if(!isset($_POST["userMessage"])) { $output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!')); die($output); } else { $user_Message = filter_var($_POST["userMessage"], FILTER_SANITIZE_STRING); } } //additional php validation if(isset($user_Name)) { if (strlen($user_Name) < 3) // If length is less than 3 it will throw an HTTP error. { $output = json_encode(array('type' => 'error', 'text' => 'Name is too short or empty!')); die($output); } } if(isset($_POST["userEmail"])) { if (!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation { $output = json_encode(array('type' => 'error', 'text' => 'Please enter a valid email!')); die($output); } } if(isset($_POST["userMessage"])) { if (strlen($user_Message) < 5) //check emtpy message { $output = json_encode(array('type' => 'error', 'text' => 'Too short message! Please enter something.')); die($output); } } Server settings $mail->isSMTP(); // Send using SMTP $mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'kristef4567@gmail.com'; // SMTP username $mail->Password = 'wlrd lyvc qdrw zebe'; // SMTP password $mail->SMTPSecure = 'TLS'; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted $mail->Port = 587; // TCP port to connect to //Recipients $mail->setFrom($user_Email,$user_Name); $mail->addAddress($your_email, 'Theme Industry'); // Add a recipient $mail->addReplyTo($your_email, 'Information'); // Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'New Contact Inquiry from your Website'; $mail->Body = "

Hi There! You have a new inquiry from your website.



"; if(isset($_POST["userEmail"])) { $mail->Body .= "Email: " . $user_Email . "
"; } //education if(isset($_POST["fatherName"])) { $mail->Body .= "Father Name: " . $father_Name . "
"; } if(isset($_POST["userAddress"])) { $mail->Body .= "Address: " . $user_Address . "
"; } if(isset($_POST["course"])) { $mail->Body .= "Applied Course: " . $applied_Course . "
"; } if(isset($_POST["userPhone"])) { $mail->Body .= "Phone: " . $user_Phone . "
"; } if(isset($_POST["userSubject"])) { $mail->Body .= "Subject: " . $user_Subject . "
"; } if(isset($_POST["userCity"])) { $mail->Body .= "City Or Country: " . $user_City . "
"; } if(isset($_POST["projectType"])) { $mail->Body .= "Project Type: " . $pro_type . "
"; } if(isset($_POST["quoteBudget"])) { $mail->Body .= "Budget: " . $budget . "
"; } //Directory listing if(isset($_POST["propertyId"])) { $mail->Body .= "Property Id: " . $property_id . "
"; } if(isset($_POST["propertyType"])) { $mail->Body .= "Property Type: " . $property_type . "
"; } // dental if(isset($_POST["service"])) { $mail->Body .= "Service Type: " . $service . "
"; } //Reservation , spa , medical template if(isset($_POST["reservationDate"])) { $mail->Body .= "Reservation Date: " . $res_date . "
"; } //spa if(isset($_POST["reserveTime"])) { $mail->Body .= "Reserved Time: " . $res_time . "
"; } if(isset($_POST["totalPeople"])) { $mail->Body .= "Total People: " . $total_people . "
"; } //medical if(isset($_POST["userGender"])) { $mail->Body .= "Gender: " . $user_gender . "
"; } $mail->Body .= '
'; if(isset($_POST["userMessage"])) { $mail->Body .= "Message:

" . $user_Message . "

"; } $mail->Body .= 'Best Regards,
'; if(isset($user_Name)) { $mail->Body .= $user_Name . "
"; } if(isset($_POST["quoteName"])) { $mail->Body .= "Quote Name: " . $quote_Name . "
"; } $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->send()) { $output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.')); die($output); }else{ $output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_Name .' Thank you for contacting us.')); die($output); } } ?>