<?php
use PHPMailer\PHPMailer\PHPMailer;
if($_POST)
{
require_once "PHPMailer/Exception.php";
require_once "PHPMailer/PHPMailer.php";
require_once "PHPMailer/SMTP.php";
$mail = new PHPMailer();
$your_email = "your@mail.ru";
//check if its an ajax request, exit if not
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
//exit script outputting json data
$output = json_encode(
array(
'type'=>'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' => 'Пожалуйста, заполните все поля!'));
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' => 'Пожалуйста, заполните все поля!'));
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' => 'Пожалуйста, заполните все поля!'));
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' => 'Пожалуйста, заполните все поля!'));
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' => 'Пожалуйста, заполните все поля!'));
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' => 'Пожалуйста, заполните все поля!'));
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' => 'Пожалуйста, заполните все поля!'));
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' => 'Пожалуйста, заполните все поля!'));
die($output);
}
else {
$user_Phone = $_POST["userPhone"];
}
}
if(isset($_POST["userSubject"])) {
if(!isset($_POST["userSubject"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Пожалуйста, заполните все поля!'));
die($output);
}
else {
$user_Subject = $_POST["userSubject"];
}
}
if(isset($_POST["userCity"])) {
if(!isset($_POST["userCity"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Пожалуйста, заполните все поля!'));
die($output);
}
else {
$user_City = $_POST["userCity"];
}
}
if(isset($_POST["projectType"])) {
if(!isset($_POST["projectType"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Пожалуйста, заполните все поля!'));
die($output);
}
else {
$pro_type = $_POST["projectType"];
}
}
//Directory listing
if(isset($_POST["propertyId"])) {
if(!isset($_POST["propertyId"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Пожалуйста, заполните все поля!'));
die($output);
}
else {
$property_id = $_POST["propertyId"];
}
}
if(isset($_POST["propertyType"])) {
if(!isset($_POST["propertyType"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Пожалуйста, заполните все поля!'));
die($output);
}
else {
$property_type = $_POST["propertyType"];
}
}
if(isset($_POST["quoteBudget"])) {
if(!isset($_POST["quoteBudget"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Пожалуйста, заполните все поля!'));
die($output);
}
else {
$budget = $_POST["quoteBudget"];
}
}
//consultant template
if(isset($_POST["service"])) {
if(!isset($_POST["service"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Пожалуйста, заполните все поля'));
die($output);
}
else {
$service = $_POST["service"];
}
}
//Reservation template
if(isset($_POST["reservationDate"])) {
if(!isset($_POST["reservationDate"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Пожалуйста, заполните все поля'));
die($output);
}
else {
$res_date = $_POST["reservationDate"];
}
}
if(isset($_POST["totalPeople"])) {
if(!isset($_POST["totalPeople"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Пожалуйста, заполните все поля!'));
die($output);
}
else {
$total_people = $_POST["totalPeople"];
}
}
//spa
if(isset($_POST["reserveTime"])) {
if(!isset($_POST["reserveTime"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Пожалуйста, заполните все поля!'));
die($output);
}
else {
$res_time = $_POST["reserveTime"];
}
}
//medical
if(isset($_POST["userGender"])) {
if(!isset($_POST["userGender"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Поля ввода пусты!'));
die($output);
}
else {
$user_gender = $_POST["userGender"];
}
}
if(isset($_POST["userMessage"])) {
if(!isset($_POST["userMessage"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Поля ввода пусты!'));
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' => 'Заполните поле Имя!'));
die($output);
}
}
if(isset($_POST["userEmail"])) {
if (!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
{
$output = json_encode(array('type' => 'error', 'text' => 'Пожалуйста, заполните все поля!!'));
die($output);
}
}
if(isset($_POST["userMessage"])) {
if (strlen($user_Message) < 5) //check emtpy message
{
$output = json_encode(array('type' => 'error', 'text' => 'Заполните поле Сообщение!'));
die($output);
}
}
//contact us form
$(".contact_btn").on('click', function () {
//disable submit button on click
// $(".contact_btn").attr("disabled", "disabled");
// $(".contact_btn b").text('Sending');
$(".contact_btn i").removeClass('d-none');
//simple validation at client's end
var post_data, output;
var proceed = "true";
// var allBlank;
var str = $('#contact-form-data').serializeArray();
$('#contact-form-data input').each(function() {
if(!$(this).val()){
// alert('Some fields are empty');
proceed = "false";
}
});
//everything looks good! proceed...
if (proceed === "true") {
var pathArray = window.location.pathname.split('/');
var secondLevelLocation = pathArray[3];
var accessURL;
if(secondLevelLocation){
accessURL="/contact-mailer.php";
}else{
accessURL="/contact-mailer.php";
}
//data to be sent to server
$.ajax({
type: 'POST',
// url: 'vendor/contact-mailer.php',
url: accessURL,
data: str,
dataType: 'json',
success: function (response) {
if (response.type == 'error') {
output = '<div class="alert-danger" style="padding:10px 15px; margin-bottom:30px;">' + response.text + '</div>';
} else {
output = '<div class="alert-success" style="padding:10px 15px; margin-bottom:30px;">' + response.text + '</div>';
//reset values in all input fields
$('.contact-form input').val('');
$('.contact-form textarea').val('');
}
if ($("#result").length) {
// alert("yes");
$("#result").hide().html(output).slideDown();
$(".contact_btn i").addClass('d-none');
}else{
if (response.type == 'error') {
Swal.fire({
type: 'error',
icon: 'error',
title: 'Oops...',
html: '<div class="text-danger">'+ response.text +'</div>',
})
$(".contact_btn i").addClass('d-none');
}else{
Swal.fire({
type: 'success',
icon: 'success',
title: 'Success!',
html: '<div class="text-success">'+ response.text +'</div>',
})
$(".contact_btn i").addClass('d-none');
}
}
},
error: function () {
alert("Failer");
}
});
}
else
{
if ($("#result").length) {
// alert("yes");
output = '<div class="alert-danger" style="padding:10px 15px; margin-bottom:30px;">Пожалуйста, заполните все поля.</div>';
$("#result").hide().html(output).slideDown();
$(".contact_btn i").addClass('d-none');
}else{
Swal.fire({
icon: 'error',
type: 'error',
title: 'Oops...',
html: '<div class="text-danger">Пожалуйста, заполните все поля.</div>'
})
$(".contact_btn i").addClass('d-none');
}
}
});
//modal window form
$(".modal_contact_btn").on('click', function () {
//disable submit button on click
// $(".modal_contact_btn").attr("disabled", "disabled");
// $(".modal_contact_btn b").text('Sending');
$(".modal_contact_btn i").removeClass('d-none');
//simple validation at client's end
var post_data, output;
var proceed = "true";
var str=$('#modal-contact-form-data').serializeArray();
$('#modal-contact-form-data input').each(function() {
if(!$(this).val()){
proceed = "false";
}
});
//everything looks good! proceed...
if (proceed === "true") {
var pathArray = window.location.pathname.split('/');
var secondLevelLocation = pathArray[3];
var accessURL;
if(secondLevelLocation){
accessURL="/contact-mailer.php";
}else{
accessURL="/contact-mailer.php";
}
//data to be sent to server
$.ajax({
type : 'POST',
// url : '/contact-mailer.php',
url : accessURL,
data : str,
dataType: 'json',
success: function(response) {
if (response.type == 'error') {
output = '<div class="alert-danger" style="padding:10px 15px; margin-bottom:30px;">' + response.text + '</div>';
} else {
output = '<div class="alert-success" style="padding:10px 15px; margin-bottom:30px;">' + response.text + '</div>';
//reset values in all input fields
$('#modal-contact-form-data input').val('');
$('#modal-contact-form-data textarea').val('');
}
if ($("#quote_result").length) {
$("#quote_result").hide().html(output).slideDown();
$(".modal_contact_btn i").addClass('d-none');
}else{
if (response.type == 'error') {
Swal.fire({
type: 'error',
icon: 'error',
title: 'Oops...',
html: '<div class="text-danger">'+ response.text +'</div>',
})
$(".modal_contact_btn i").addClass('d-none');
}else{
Swal.fire({
type: 'success',
icon: 'success',
title: 'Success!',
html: '<div class="text-success">'+ response.text +'</div>',
})
$(".modal_contact_btn i").addClass('d-none');
}
}
// $("#quote_result").hide().html(output).slideDown();
// $(".modal_contact_btn i").addClass('d-none');
},
error: function () {
alert("Failer");
}
});
}
else {
// output = '<div class="alert-danger" style="padding:10px 15px; margin-bottom:30px;">Please provide the missing fields.</div>';
// $("#quote_result").hide().html(output).slideDown();
// $(".modal_contact_btn i").addClass('d-none');
if ($("#quote_result").length) {
// alert("yes");
output = '<div class="alert-danger" style="padding:10px 15px; margin-bottom:30px;">1Пожалуйста, заполните все поля.</div>';
$("#quote_result").hide().html(output).slideDown();
$(".modal_contact_btn i").addClass('d-none');
}else{
Swal.fire({
icon: 'error',
type: 'error',
title: 'Oops...',
html: '<div class="text-danger">2Пожалуйста, заполните все поля.</div>'
})
$(".modal_contact_btn i").addClass('d-none');
}
}
});
<script>
jQuery(document).ready(function() {
jQuery("#heyhey").change(function() {
if(jQuery(this).find("option:selected").val()) {
jQuery(".vybor").hide();
}
});
});
</script>
<a class="k_nazad" href="javascript:void(0)" onclick="showHide('vybor')"><span class="nazad_k">Назад</span></a>
<script type="text/javascript">
function showHide(element_id) {
if (document.getElementById(element_id)) {
var obj = document.getElementById(element_id);
if (obj.style.display != "none") {
obj.style.display = "none";
}
else obj.style.display = "block";
}
else alert("Элемент с id: " + element_id + " не найден!");
}
</script>
Собственно вопрос, почему не работает вторая форма? Первая форма работает отлично, она и была изначально, вторую я добавил сам, и видимо криво? При отправке сообщения со второй формы пишет ошибку из php обработчика: "Could not send mail! Please check your PHP mail configuration.". Первая форма отправляется отлично...