2

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!

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
HelloWorld
  • 2,480
  • 3
  • 28
  • 45

2 Answers2

2

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:

Community
  • 1
  • 1
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
0

If you want send a email you by function mail(). you must set the configuration. like the answer above. So I suggest you send your email by SMTP. It's easy to send without configuration. You just need to register a private email such as Email or Yahoo.

From this Question

  // Pear Mail Library    require_once "Mail.php";

  $from = '<your@mail.com>'; //change this to your email address  $to =
'<someone@mail.com>'; // change to address    $subject = 'Insert subject
here'; // subject of mail     $body = "Hello world! this is the content
of the email"; //content of mail

  $headers = array(
      'From' => $from,
      'To' => $to,
      'Subject' => $subject   );


  $smtp = Mail::factory('smtp', array(
          'host' => 'ssl://smtp.gmail.com',
          'port' => '465',
          'auth' => true,
          'username' => 'your@gmail.com', //your gmail account
          'password' => 'snip' // your password
      ));

    // Send the mail  $mail = $smtp->send($to, $headers, $body);
General Grievance
  • 4,555
  • 31
  • 31
  • 45
Ning.Lin
  • 1
  • 1