php Mail在部署到生产时无法正常工作

时间:2016-11-22 15:49:37

标签: php jquery ajax

我有最新版本的PHP和JQuery,我也使用AJAX来处理这个请求。

这是我的PHP代码:

<?php
  if(count($_POST) > 0) {
  $to = "adam3692@hotmail.co.uk";
  $subject = "Website Enquiry";
  $first_name = $_POST['first_name'];
  $last_name  = $_POST['last_name'];
  $email      = $_POST['email'];
  $phone      = $_POST['phone'];
  $message    = $_POST['message'];
  $header     = "Content-type: text/html\r\nReply-To: $email\r\nFrom: $first_name <$email>";

  $body ="Email recieved from ".$first_name." ".$last_name."<br /><hr />containing the following message: <br /> <div align='center'>".$message."</div><br /><hr />The following details were attached<br /><b>Email</b>: ".$email."<br /><b>Phone</b>: ".$phone;

if(mail($to, $subject, $body, $header)) {
  die("true");
} else {
  die("There was an error sending the email!");
}

} ?&GT;

这是我的JQuery:

function setText( text ){
  $("#email-send").html(text);
}

  var isSubmitting = false;
$("#email-send").click(function() {

if( isSubmitting == false ){
  isSubmitting = true;
  var firstName = $("#first-name").val();
  var lastName  = $("#last-name").val();
  var email     = $("#email").val();
  var phone     = $("#phone").val();
  var message   = $("#message").val();

  if( firstName == "" || lastName == "" || email == "" || phone == "" )
    alert("Contact form not complete");
  else {
    setText("Sending...");
    $.post("email.php", {
      first_name: firstName, last_name: lastName, email: email, phone: phone, message: message
    }, function(data) {
      if(data == "true"){
        setText("Sent!");
      } else {
        setText("Send mail");
        alert(data);
      }
    });
  }
} else {
  alert("You can only send 1 email at a time!");
}

});

我无法弄清楚如何调试这个,因为我只返回“发送电子邮件时发生了错误!”消息,我是使用PHP的新手。

有没有人知道这可能是什么,如果有帮助,我已经部署到Heroku。

0 个答案:

没有答案