Skip to content

Instantly share code, notes, and snippets.

@Mons1eurEnzo
Last active September 4, 2022 20:29
Show Gist options
  • Save Mons1eurEnzo/3665398d9e20a8bdd7967d6f1d62d7d6 to your computer and use it in GitHub Desktop.
Save Mons1eurEnzo/3665398d9e20a8bdd7967d6f1d62d7d6 to your computer and use it in GitHub Desktop.
html, php, jQuery(AJAX) - Форма обратной связи
$(document).ready(function() {
$("#form").submit(function() {
$.ajax({
type: "POST",
url: "mail.php",
data: $(this).serialize()
}).done(function() {
$(this).find("input").val("");
alert("Спасибо за заявку! Скоро мы с вами свяжемся.");
$("#form").trigger("reset");
});
return false;
});
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Отправка форм AJAX</title>
</head>
<body>
<form id="form">
<input type="text" name="name" placeholder="Ваше имя" required /><br />
<input type="text" name="phone" placeholder="Ваш телефон" required /><br />
<button>Отправить</button>
</form>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="common.js"></script>
</body>
</html>
<?php
$recepient = "agragregra@ya.ru";
$sitename = "Название сайта";
$name = trim($_POST["name"]);
$phone = trim($_POST["phone"]);
$text = trim($_POST["text"]);
$message = "Имя: $name \nТелефон: $phone \nТекст: $text";
$pagetitle = "Новая заявка с сайта \"$sitename\"";
mail($recepient, $pagetitle, $message, "Content-type: text/plain; charset=\"utf-8\"\n From: $recepient");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment