<form method="POST" id="form" name="form" action="php/main.php">
<div class="input-1">
<label for="">Имя:</label>
<input type="text" placeholder="Иван" autofocus="autofocus" required="required" name="name" id="name">
</div>
<div class="input-1">
<label for="">Отчество:</label>
<input type="text" placeholder="Иванович" required="required" name="second" id="second">
</div>
<div class="email">
<label for="email">Email:</label>
</div>
<input type="email" placeholder="example@mail.ru" required="required" name="email" id="email">
<div class="message">
<label for="area">Сообщение:</label>
</div>
<textarea cols="30" rows="10" placeholder="Введите сообщение..." required="required" name="message" id="message"></textarea>
<div class="sbm">
<input type="submit" name="submit" value="Отправить">
</div>
</form>
<?php
$name = $_POST["name"];
$second = $_POST["second"];
$email = $_POST["email"];
$message = $_POST["message"];
$to = "krasnov.alexey96@gmail.com";
$subject = "A new message from website!";
$body = "Имя:" . $name ."\n" . "Отчество:" . $second ."\n" . "Имейл: " .$email ."\n" . "Сообщение:" . $message;
$header = "From :" . $email;
mail($to, $subject, $body, $header);
?>
$(document).ready(function(){
$('#form').submit(function(e) {
var $form = $(this);
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize()
}).done(function(){
$(".php-success").css('background', 'green');
$(".php-success p").replaceWith("<p class='item'>Письмо успешно отправлено!</p>")
$(".php-success").animate({
top: 0
},500);
setTimeout(function() {
$(".php-success").animate({
top: "-" + 50 + "px"
},500);
},3000);
}).fail(function(){
$(".php-success").css('background', '#AD1114');
$(".php-success p").replaceWith("<p class='item'>Неудачно... Свяжитесь по контактам ниже.</p>")
$(".php-success").animate({
top: 0
},500);
setTimeout(function() {
$(".php-success").animate({
top: "-" + 50 + "px"
},500);
},3000);
});
e.preventDefault();
});
});