简体   繁体   中英

PHP isn't sending mail

I am building a website using a Linode VPS.

I am using Apache and PHP installed using:

apt-get install apache2 php

This is the HTML form:

  <form action="" class="form-horizontal" method="post">
    <div class="form-group">
      <label class="col-sm-2 control-label">Name</label>
      <div class="col-sm-10">
        <input type="email" class="form-control" name="name" placeholder="Name">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">Email</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" name="email" placeholder="Email">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">IP</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" disabled>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">Message</label>
      <div class="col-sm-10">
        <textarea class="form-control" rows="4" name="message"></textarea>
      </div>
    </div>
    <div class="form-group">
      <div class="col-sm-offset-2 col-sm-10">
        <button type="submit" class="btn btn-default">Submit</button>
      </div>
    </div>
  </form>

This is the PHP attempting to send mail:

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

if(isset($_POST['email'])) {
  $email_to = "webmaster@domain.com";
  $email_subject = "Contact Form";

  $name = $_POST['name'];
  $email = $_POST['email'];
  $ip = $_POST['ip']; 
  $message = $_POST['message']; 


  $email_message  = "Name: ".$name."\n";
  $email_message .= "Email: ".$email."\n";
  $email_message .= "IP: ".$ip."\n";
  $email_message .= "Message: ".$message."\n";

  $headers = 'From: '.$email."\r\n".
             'Reply-To: '.$email."\r\n" .
             'X-Mailer: PHP/' . phpversion();

mail($email_to, $email_subject, $email_message, $headers);  
?>
<div class="panel panel-success">
  <div class="panel-body">
    Message sent.
  </div>
</div>
<?php

}

?>

The problem is that no e-mail is received and no e-mail is marked as spam.

I added PHP error reporting:

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

which doesn't report any errors.

First you should say which mailer is configurated on your server. Secoundary i'd check if that mailer and the correct path is indicated in the php.ini config file. Just a starting point...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM