PHP电子邮件表单几乎可以[重复]

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>

I tried your code and it worked for me? Just check everything is being posted correctly. You're probably missing a value e.g. email address.

<?php

$field_name = $_POST['InputName'];
$field_email = $_POST['InputEmail'];
$field_message = $_POST['InputMessage'];

$mail_to = 'youremail@example.com';
$subject = 'Message from a site visitor '.$field_name;

$body_message = "From: [from]
Email: [emailaddress]
Message: [message]";

$headers = 'From: email@example.com'."
";
$headers .= 'Reply-To: email@example.com'."
";

$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
}
?>