I have a website with a form where you can send a message to my email adress. But it doesn't work yet. I am not really sure what is required to do this. Here is what i have done so far:
The PHP:
<?php
if (isset($_POST['from']) && isset($_POST['header']) && isset($_POST['message'])) {
$to = "example@awesomemail.com";
$subject = $_POST['from'];
$body = $_POST['message'];
$headers = $_POST['header'];
if (mail($to, $subject, $body, $headers)) {
echo("<p>Email successfully sent!</p>");
echo json_encode('success');
} else {
echo("<p>Email delivery failed…</p>");
echo json_encode('failed');
}
}
?>
The JS:
$.ajax({
type : "POST",
url : "sendmail.php",
data: {"from": from, "header": header, "message": message},
dataType: "json",
success: function(msg){
alert(msg);
}
});
Is there something wrong with my code or am i missing something? The email is supposed to be sent to a gmail account.