I'm trying to email the contents of a JS array by encoding using JSON.stringify and then decoding in the PHP which should then be sent via email. I get a success alert that the data is sent to the PHP okay, but the email doesn't come through. Can anybody spot anything glaringly obvious I'm missing/got wrong, please?
Array has been populated via .push function and I can output that fine in the HTML, so I know it's populated.
Using ajax to encode my data string:
dataString = myArray;
var jsonString = JSON.stringify(dataString);
$.ajax({
type: "POST",
url: "script.php",
data: {data : jsonString},
cache: false,
success: function(){
alert("Success");
}
});
Then in the PHP:
<?php
$data = json_decode(stripslashes($_POST['data']));
$to = "[email protected]";
$header = "Content-Type: text/html\r\nReply-To";
$subject = "This is my Subject Line";
$body =
@"
<strong>The data is:</strong> $data
";
if(mail($to, $subject, $body, $header)) {
die("true");
} else {
die("There was an error sending the email.");
}
?>
The email doesn't come through at all, and I don't get any error messages at all. Can anybody help, please? Thanks!