We inherited a PHP script that posts to an endpoint using curl. The original developers are out of touch, and the client isn't clear on what it does - just that they want to keep it the way it is.
The script worked fabulously, until recently when we updated the site's domain name. The only other change I can think of that might've affected it is adding an SSL certificate, I don't think we re-tested the email function after that point, which means it could've been broken since then.
Copy and pasting the script below. If you like to take a look and let me know what you think is going wrong, that would be really helpful :) (The company domain name has been removed and replaced with "XXXX" to honor their privacy.)
Edit: I believe the php script below might not even be running - adding the js that calls it below. The issue may be with the $.post method....
sendmail.blade.php
@php
$fullName = $_POST["fullName"];
$user_number = $_POST["user_number"];
$email = $_POST["email"];
$daytimePhoneNumber = $_POST["daytimePhoneNumber"];
$m = $_POST["message"];
$xml = <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<ContactUs>
<Source>Corporate Site</Source>
<Name>$fullName</Name>
<MemberNumber>$user_number</MemberNumber>
<eMail>$email</eMail>
<Phone>$daytimePhoneNumber</Phone>
<Comments>$m</Comments>
</ContactUs>
EOD;
$fields = array("xml"=>$xml);
$url = "https://prod-rest.XXXX.org/ContactService.svc/PostContact";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); // use HTTP POST to send form data
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. ###
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$resp = curl_exec($ch); //execute post and get results
curl_close ($ch);
$handle = fopen($_SERVER["DOCUMENT_ROOT"]."/xmlanswer.html", 'w');
fwrite($handle, $resp);
fclose($handle);
if(strpos($resp,"<ERRORDESCRIPTION>Success</ERRORDESCRIPTION>")!==false) {
echo "ok";
} else if(strpos($resp,"<ERRORDESCRIPTION>")!==false) {
$pos1 = strpos($resp,"<ERRORDESCRIPTION>")+18;
$pos2 = strpos($resp,"</ERRORDESCRIPTION>",$pos1);
echo substr($resp,$pos1,$pos2-$pos1);
} else {
echo $resp;
} exit;
@endphp
post_submit_contact.js
$(function(){
var submittedFlag = false;
$('#contact-form').submit(function() {
var msg,
form = $(this);
// check that url exists
$.get("/wp-content/themes/quorum-theme/sendmail.blade.php").done(function () {
console.log("url ok");
}).fail(function () {
console.log("url failed");
});
if (!submittedFlag) {
submittedFlag = true;
document.form1.submit.disabled = true;
$.post('/wp-content/themes/quorum-theme/sendmail.blade.php', form.serialize(),
function (data) {
msg = "_____________________________________\n\n";
msg += "Your request has been submitted\n";
msg += "Our administration business hours are\n";
msg += "Monday-Friday (excluding holidays)\n";
msg += "8:30 a.m. 7:00 p.m. ET.\n";
msg += "_____________________________________\n\n\n";
alert(msg);
form[0].reset();
$('.input-container').removeClass('no-error');
$('#myCounter').html(600);
});
return false;
} else {
alert("You have already submitted this form; please wait for the submission to complete.");
return false;
}
});
});