Why ajax form not sending mail?

Here is my code



 <meta charset="UTF-8">
<title>uniMail</title>



<form>

 <!-- Required Hidden Fields -->
 <input type="hidden" name="project_name" value="Site Name">
 <input type="hidden" name="admin_email" value="betti@mail.ru">
 <input type="hidden" name="form_subject" value="Form Subject">
 <!-- END Hidden Required Fields -->

 <input type="text" name="Name" placeholder="You name..." required><br>
 <input type="text" name="email" placeholder="your email..." required><br>
 <input type="text" name="Phone" placeholder="your phone..."><br>
<button>Send</button>

</form>

 <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
 <script src="script.js"></script>




$(document).ready(function() {

 //E-mail Ajax Send
 $("form").submit(function() { //Change
 var th = $(this);
$.ajax({
 type: "POST",
 url: "mail.php", //Change
 data: th.serialize()
 }).done(function() {
 alert("Thank you!");
 setTimeout(function() {
 // The Done Functions
th.trigger("reset");
 }, 1000);
});
 return false;
});

});


<?php

$method = $_SERVER['REQUEST_METHOD'];

//Script Foreach
$c = true;
if ( $method === 'POST' ) {

 $project_name = trim($_POST["project_name"]);
 $admin_email = trim($_POST["admin_email"]);
 $form_subject = trim($_POST["form_subject"]);

 foreach ( $_POST as $key =--> $value ) {
 if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
 $message .= "
 ". ( ($c = !$c) ? ":" ) . "
<b>$key</b>
$value

";
}
}
} else if ( $method === 'GET' ) {

 $project_name = trim($_GET["project_name"]);
 $admin_email = trim($_GET["admin_email"]);
 $form_subject = trim($_GET["form_subject"]);

 foreach ( $_GET as $key => $value ) {
 if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
 $message .= "
 ". ( ($c = !$c) ? ":" ) . "
<b>$key</b>
$value

";
}
}
}

$message = "$message<table style="width: 100%;"></table>";

function adopt($text) {
 return '=?UTF-8?B?'.Base64_encode($text).'?=';
}

$headers = "MIME-Version: 1.0" . PHP_EOL .
"Content-Type: text/html; charset=utf-8" . PHP_EOL .
'From: '.adopt($project_name).' <'.$admin_email.'>' . PHP_EOL .
'Reply-To: '.$admin_email." . PHP_EOL;

mail($admin_email, adopt($form_subject), $message, $headers );


And here is my error
ee74d0ea8ff743cea6c00b95d81aaf39.png

Form comes in the mail. Why?
June 26th 19 at 13:59
1 answer
June 26th 19 at 14:01
See access.log server whether the request to PHP
Do debugging on the server in PHP - for example, using error_log() and see the error.log server - if there are any errors in PHP

Always duplicate mail sending record in the log or even do upload a copy of all sent emails in a separate file if e-mails are not sent for some reason.

Find more questions by tags AJAX