let name = document.querySelector('#name').value;
let mail = document.querySelector('#mail').value;
let data= {
'name': name,
'mail': mail
};
fetch('contact.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8',
},
body: JSON.stringify(data)
});
//contact.php
<?php
$message = '';
$message .= '<p>Name: '. $_POST['name'] .'</p>';
$message .= '<p>Mail: '.$_POST['mail'].'</p>';
print_r($message);
?>