PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 8, 2022

[FIXED] How to send an email with $_POST data submitted with AJAX

 November 08, 2022     ajax, email, javascript, php     No comments   

Issue

I want to submit some data from localStorage to

Autoform.submitStoredData = function() {
    var data = localStorage.tbRecoveredData;
    if(data) {
        jQuery.ajax ({
            type: "POST",
            url:"http://www.thewebsite.com/Autoform.php",
            data: data,
            success: function() {
                console.log("success");
            },
            error: function(xhr,status,error) {
                console.log("payload failed to submit with xhr: " + xhr + ", status: " + status + ", and error: " + error);
            }
        });
        localStorage.removeItem("tbRecoveredData");
    }
};

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

<?php

    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $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!


Solution

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

var_dump(mail(...));

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:

  • PHP mail() function enable
  • PHP Mail Configuration
  • How to configure PHP to send e-mail?


Answered By - Praveen Kumar Purushothaman
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing