let form = document.querySelector('form')
form.addEventListener('submit', submitHandler)
function submitHandler(){
fetch("mail.php", {
method: "POST",
body: new FormData(form)
})
.then(response => response.json())
.then(function(json) { /* process your JSON further */ })
.catch(function(error) { console.log(error);
});
preventDefault;
}
<form action="">
<input type="text" name="name">
<button type="submit">отправить</button>
</form>
<script>
let form = document.querySelector('form')
form.addEventListener('submit', submitHandler)
function submitHandler(){
fetch("mail.php", {
method: "POST",
body: new FormData(form)
})
.then(response => response.json())
.then(function(json) { /* process your JSON further */ })
.catch(function(error) { console.log(error); });
}
</script>
<?php
$recepient = "mail@yandex.ru";
$sitename = "Название сайта";
$name = trim($_POST["name"]);
$message = "Имя: $name;
$pagetitle = "Новая заявка с сайта \"$sitename\"";
mail($recepient, $pagetitle, $message, "Content-type: text/plain; charset=\"utf-8\"\n From: $recepient");