<?php
header('Content-Type: text/html; charset=utf-8');
// Variables
$name = trim($_POST["name"]);
$mail = trim($_POST["mail"]);
$pattern = "/(content-type|bcc:|cc:|to:)/i";
$to = 'example@example.com';
$sub = "=?utf-8?B?". base64_encode("topic of the letter"). "?="; // You can define email subject
// HTML Elements for Email Body
$body = "Name: $name<br>Email: $mail<br>";
//Must end on first column
$headers = "From: example@example.com" ."\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
// PHP email sender
mail($to, $sub , $body, $headers);
?>
AJAX
<script>
$(document).ready(function() {
//E-mail Ajax Send
$("form.callback").submit(function() { //Change
var th = $(this);
$.ajax({
type: "POST",
url: "mail.php", //Change
data: th.serialize()
}).done(function() {
alert('Success');
setTimeout(function() {
// Done Functions
th.trigger("reset");
}, 1000);
});
return false;
});
});
</script>