HelloWorld HelloWorld - 1 year ago 123
Ajax Question

How to send an email with $_POST data submitted with AJAX

I want to submit some data from localStorage to

Autoform.submitStoredData = function() {
var data = localStorage.tbRecoveredData;
if(data) {
jQuery.ajax ({
type: "POST",
data: data,
success: function() {
error: function(xhr,status,error) {
console.log("payload failed to submit with xhr: " + xhr + ", status: " + status + ", and error: " + error);

I am getting "success" in the console so far so good. Autoform PHP looks like this:


$data = $_POST;
mail('myemail@gmail.com', 'OK SO here at least is the captured string', $data);


This does nothing or at least no email gets sent. I admit I dont know much about PHP, I've tried googling without much luck. Do I need to wrap this in a sort of self invoking function or something because it seems like the PHP code is not being executed. Any help is appreciated thanks!

Answer Source

Okay, if you try putting the below code and finding it to be NULL:


Then you need to configure your server to make the PHP work with it's built in mail() function. There are several ways to do it:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download