I'm trying to create a simple form for sending an email with ajax call. I can get into ajax's success, however I don't get a message. I'll post my code, could you tell me where the problem is?
html
`<input type="text" name="name" id="name">
<label for="name">Name</label><br>
<input type="text" name="email" id="email">
<label for="email">email</label><br>
<input id="submit" type="submit" value="click me">`
js
<script>
$(document).ready(function(){
$("#submit").click(function(){
$.ajax({
"method": "POST",
"url": "test.php" ,
"data": {
name : $("#name").val(),
email : $("#email").val()
},
success: function(){
alert("message send")
},
error : function(iqXHR, textStatus, errorThrown){
alert(
"iqXHR.status: " + iqXHR.status + "\n" +
"textStatus: " + textStatus + "\n" +
"errorThrown: " + errorThrown
)
}
})
})
});
</script>
php
<?php
$name = $_POST["name"];
$email = $_POST["email"];
mail("test@gmail.com","Mail from:" .$email,"Test Message");
?>