简单的联系表单不发送邮件与PHP mail()函数[重复]

This question already has an answer here:

HTML:

<form action="php/send-contact.php" class="contact-form" name="contact-form" method="post">
  <div class="row">
    <div class="col-sm-6 cols">
      <input type="text" name="name" required="required" placeholder="Name*">
    </div>
    <div class="col-sm-6 cols">
      <input type="email" name="email" required="required" placeholder="Email*">
    </div>
    <div class="col-sm-6 cols">
      <input type="text" name="subject" required="required" placeholder="Subject*">
    </div>
    <div class="col-sm-12 cols">
      <textarea name="message" required="required" cols="30" rows="5" placeholder="Message*"></textarea>
    </div>
    <div class="col-sm-12 cols">
      <input type="submit" name="submit" value="Send Message" class="btn btn-send">
    </div>
  </div>
</form>

php/send-contact.php:

<?php
$name = @trim(stripslashes($_POST['name'])); 
$email = @trim(stripslashes($_POST['email']));
$subject = @trim(stripslashes($_POST['subject']));
$message = @trim(stripslashes($_POST['message'])); 
$email_from = $email;
$email_to = 'hello@domain.co.uk';//replace with your email
$body = 'Name: ' . $name . "

" . 'Email: ' . $email . "

" . 'Subject: ' . $subject . "

" . 'Message: ' . $message;
$success = @mail($email_to, $body, 'Name: ' . $name . "

" . 'Email: ' . $email . "

" . 'Subject: ' . $subject . "

" . 'Message: ' . $message);
?>
<!DOCTYPE HTML>
<html lang="en-US">

  <head>
    <script>
      alert("Thank you for getting in touch. We will contact you as soon as possible.");

    </script>
    <meta HTTP-EQUIV="REFRESH" content="0; url=../index.html">
  </head>

The HTML alert activates and refreshes as it should, but it doesnt send any email...

I have tried numerous email address recipients.

Also, are there any special measures I should take into account (regarding the PHP elements) when adding Google ReCaptcha to this form?

</div>

So I have tested this, and I think it is doing what you want.

$name = htmlentities($_POST['name']);
$email_from = htmlentities($_POST['email']);  
$subject = htmlentities($_POST['subject']); 
$message = htmlentities($_POST['message']); 

$email_to = 'Admin@Domain.com';//replace with your email

$headers = "From: webmaster@example.com" . "
" . "CC: ". $email_from; //This adds a from field, as well as CC's the person submitting the request.


//Build the body of the eamil
$body = 'Name: ' . $name . "

" . 'Email: ' . $email_from . "

" . 'Subject: ' . $subject . "

" . 'message: ' . $message;

$success = mail($email_to, "Contact from site X, regarding: ".$subject, $body,$headers);
?>
<!DOCTYPE HTML>
<html lang="en-US">

  <head>
  <?php if($success){  //If the email was sent correctly?> 
    <script>

      alert("Thank you for getting in touch. We will contact you as soon as possible.");

    </script>

    <?php header('Location: ../index.html'); }else{?>
        <script>

            alert("There was an error when sending the email, please try again later.");

    </script>

<?php header('Location: ../index.html');  } //If the email falied?>
  </head>

The other file (the html) remains the same. Simply replace your code in php/send-contact.php with this.