I am trying to send an email to myself using Ajax and PHP. The following seems to be sending the email but doesn't seem to pass the variables into PHP from Javascript.
JavaScript
var aaa = $('#aaa').val();
var bbb = $('#bbb').val();
var data = 'A: ' + aaa + ' B: ' + bbb;
$.ajax({
type: "POST",
url: "sendMail.php",
data: data,
success: function(){
alert("Email Sent");
}
});
PHP Code:
<?php
$subject = $_POST['data'];
mail("[email protected]", $subject, "", "From: [email protected]") or die("Error!");
?>
Could anyone please advise on how to fix this?
datais invalid. Just give it an object. Keep it simple. Let jQuery do the heavy lifting for you.