0

I have the latest version of PHP and JQuery, I'm using AJAX to handle this request also.

Here is my PHP code:

<?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!");
}

} ?>

here is my 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!");
}

});

I can't figure out how to debug this, as I am only returning the "There was an error sending the email!" message and I am fairly new to using PHP.

Does anyone here know what this could be, I have deployed to Heroku if that helps.

0 Answers0