I have setup a form to send out an email upon clicking sending. To test it, I have hard coded the values in the script. I even get a success message "Yes" when I click send but unable to receive the email. Checked that the email address is correct and checked spam folder too. Please advice if I am missing something. Thanks.
HTML
<form action="mail/contact_me.php" method="post" role="form" id="formid" class="footer-custom-form footer-custom-hr">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<input type="text" class="form-control" name="name" placeholder="Your Name..." required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" name="phone" placeholder="Phone">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="email" class="form-control" name="email" placeholder="Your Email Address" required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<textarea class="form-control" name="message" rows="8" placeholder="Your Message" required></textarea>
</div>
</div>
</div>
<div class="row">
<div class="">
<input class="footer-form-btn" type="submit" value="Send message">
</div>
</div>
</form>
JS
$(function () {
$('form#formid').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: '../mail/contact_me.php',
data: $('form#formid').serialize(),
success: function () {
alert("yes"); //<-- I get this alert after submit
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("no");
}
});
});
});
PHP
<?php
//hardcoded for testing
$name = 'testname';
$email_address = 'testemail@gmail.com';
$subject = 'testsubject';
$message = 'testmessage';
// Create the email and send the message
$to = 'myemail@gmail.com'; // I have my actual email here
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nSubject: $subject\n\nMessage:\n$message";
$headers = "From: noreply@test.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>