This question already has an answer here:
I'm using an HTML5/CSS template with a built in contact form. My contact.php file is in place and the form is working as expected except for the most important part. The email is not being sent. I might be missing a necessary line or two. Here's the form and php code, with the recipient address "name@domain.com", but no mail ever reaches the inbox. The php version is 7.2 on a greengeeks host.
<?php
$field_name = $_POST['InputName'];
$field_email = $_POST['InputEmail'];
$field_message = $_POST['InputMessage'];
$mail_to = 'name@domain.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."
";
$body_message .= 'E-mail: '.$field_email."
";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."
";
$headers .= 'Reply-To: '.$field_email."
";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to webmaster@domain.com');
window.location = 'index.html';
</script>
<?php
}
?>
</div>