I have a JS code as below :
function validateForm(){
// some code
$.get("../sendMail.php");
alert('Reached here ? then the mail was sent successfully');
// more stuff
}
and the sendMail.php code :
<?php
$to = "[email protected]";
$subject = "MY PHP MESSAGE";
$name = $_REQUEST['myName"'];
$phone = $_REQUEST['myPhone'];
$email = $_REQUEST['myEmail'];
$message .= "<br>"."<br>";
$message .= "<strong><font color='red'>Information Below.</font></strong>"."<br>"."<br>";
$message .= "<strong>Name:</strong> ".$name ."<br/>";
$message .="<strong>Phone:</strong> ".$phone."<br/>";
$message .="<strong>Email:</strong> ".$email."<br/>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: [email protected]' . "\r\n";
mail($to,$subject,$message,$headers);
?>
Even though the alert in the JS works great , the mail is not sent .
Any idea what's wrong with the code ?
Much appreciated
(FYI , I'm running on the localhost , if it makes any difference)
EDIT :
$.ajax({
url: '../sendMail.php',
success: function(data, textStatus, jqXHR){
alert(console.log('data: %O', data));
alert(console.log('textStatus: %s', textStatus));
alert(console.log('jqXHR: %O', jqXHR));
},
error: function(jqXHR, textStatus, errorThrown){
alert(console.log('jqXHR: %O', jqXHR));
alert(console.log('textStatus: %s', textStatus));
alert(console.log('errorThrown: %s', errorThrown));
}});
but nothing was sent , and nothing is being printed on the screen . No alert , nothing .
$.getcall.mail()was successful. Check the Network tab of Developer Tools to see if the script reported any errors.