php post data is always empty
i am trying to send myself an email message using jquery and php i want
the contents of the message to be decided by jquery this is my sending
code
$.ajax({
url: 'http://mywebpage.com/email.php',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data:'test',
dataType: "text",
success: function(data){
console.log(data);
console.log("IT WORKED");
},
failure: function(result){
console.log("FAILED");
console.log(result);
}
});
this is my php script
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header("Access-Control-Allow-Headers: Origin, X-Requested-With,
Content-Type, Accept");
$to = "myemail@gmail.com";
$subject = "Test mail";
$message = $_POST["data"];
echo var_dump($_POST);
echo $message;
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
the email gets sent, but the $_POST["data"] always comes back empty what
to do ?
No comments:
Post a Comment