I have a piece of code that is not working. It is a handler for POST submission. Below is the code sending data.
$.ajax({
type: 'POST',
url: '/calculator.php',
data: $('form').serialize(),
success: function(data) {
console.log(data);
}
});
The handler - calculator.php
looks like:
<?php
$parse_url = explode('wp-content', $_SERVER['SCRIPT_FILENAME']);
require_once($parse_url[0], 'wp-load');
send_email();
echo 'success';
function sendEmail() {
..
wp_mail($to, $subject, $message, $headers);
}
?>
When calculator.php
s is being invoked from the command line, it works fine. However, submitting the from with ajax or postman does nothing. I have a varnish
cache in front of my server, but it should not matter. Should it?