0

I am working on a website and almost have it all working. I've tested a javascript function to call a php email file to send a file when a contact form is filed out and send is pressed. This works flawlessly on my local xampp server, but not on the plesk server used for production. The Javascript functions are:

function emailproc()
{
     xmlHttp = new XMLHttpRequest();
 xmlHttp.open("POST", 'http://dougsguns.com/wp-content/themes/DougsGunsTheme/emailproc.php', true);
//  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 xmlHttp.onreadystatechange = function () {
     if (xmlHttp.readyState == 4) {
    //     var response =  document.getElementById('send_response');
    //    response.display = "";

    success();
       
    }
    else{
        failure();
    }
   
}
var formData = new FormData();
formData.append("txtName", document.getElementById('txtName').value);
formData.append("txtEmail", document.getElementById('txtEmail').value);
formData.append("txtCompany", document.getElementById('txtCompany').value);
formData.append("txtState", document.getElementById('txtState').value);
formData.append("txtAddress", document.getElementById('txtAddress').value);
formData.append("txtCity", document.getElementById('txtCity').value);
formData.append("txtState", document.getElementById('txtState').value);
formData.append("txtPostalCode", document.getElementById('txtPostalCode').value);
formData.append("txtPhone", document.getElementById('txtPhone').value);
formData.append("ddInterest", document.getElementById('ddInterest').value);
formData.append("txtHowFind", document.getElementById('txtHowFind').value);
formData.append("txtComments", document.getElementById('txtComment').value);
xmlHttp.send(formData);
alert("Sent");
return true;

}
function success()
{
window.location.href =  "http://dougsguns.com/success/";
}

function failure()
{
    window.location.href = "http://dougsguns.com/failure/";
}

This is supposed to get the form fields and then call emailproc.php file. It always opens the success page, but the email is never sent. The emailproc.php file is:

<?php
require_once("../../../wp-load.php");
print_r($_REQUEST);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  // collect value of input field
  $name = $_REQUEST['txtName'];
  $email = $_REQUEST['txtEmail'];
  $company =  $_REQUEST['txtCompany'];
  $state = $_REQUEST['txtState'];
  $address = $_REQUEST['txtAddress'];
  $city = $_REQUEST['txtCity'];
  $state = $_REQUEST['txtState'];
  $postal_code = $_REQUEST['txtPostalCode'];
  $phone = $_REQUEST['txtPhone'];
  $ddinterest = $_REQUEST['ddInterest'];
  $howfind = $_REQUEST['txtHowFind'];
  $comment = $_REQUEST['txtComments'];
}

$to = 'dgrd48@aol.com';
$subject = 'From Dougs Guns';
$body = "<body><h5>The following e-mail was sent from the Doug's Guns website :</h5>" .
   "<hr />" .
   "<p>Name: " . $name . "</p>" .
   "<p>Email: " . $email . "<br />Company: " . $company . "<br />Address: " . $address . "<br />" .
   "City: " . $city ."<br />State: " . $state . "<br />Postal Code: " . $postal_code . "<br />".
   "Phone: " . $phone . "<br />".
   "Interested In: " . $ddinterest . "<br /><br />".
   "Discovered Website How: " . $howfind . "<br /><br />".
   "Comment/question:<br />" . $comment . "<br /><br />"
  ;
//$headers = 'Content-Type: text/html; charset=UTF-8, From: Dougs Guns &lt;dgrd48@aol.com';
 
mail( $to, $subject, $body, $headers);
?>

This was a conversion from a .asp static website to a wordpress website. Any help would be appreciated and if you need more information please let me know. Thank you.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
greel87
  • 27
  • 4
  • `//$headers = 'Content-Type: text/html; charset=UTF-8, From: Dougs Guns <dgrd48@aol.com';` should be `$headers = 'Content-Type: text/html; charset=UTF-8, From: Dougs Guns <dgrd48@aol.com';` –  Jul 30 '20 at 21:24
  • So is the server set up the same way to handle mail? Seems like looking at the logs would be the starting point. – epascarello Jul 30 '20 at 21:26

0 Answers0