I want to execute a jQuery script after submitting a form. The jQuery script it's only a line that will fade In a hidden that will show if the e-mail have been sent or not sent.
The PHP code is at the top of the file and I don't know if staying the PHP code at the top is the problem but I tried moving de PHP above the jquery script but it doesn't work.
EDIT:
Now I have that code in my index.php
$(document).ready(function) {
$('form').submit(function) {
$.ajax({
url: "mail.php",
type: "POST",
data: {
name: $('input[name="name"]').val(),
email: $('input[name="email"]').val(),
msg: $('input[name="msg"]').val()
},
cache: false,
success: function(response) {
$('#result').html(response);
}
});
return false;
});
});
In mail.php I have that other code
$name = $_POST['name'];
$mail = $_POST['email'];
$msg = $_POST['msg'];
if(mail('[email protected]', $name, $msg)) {
echo 'Pass!';
} else {
echo 'Fail!';
}
When I executed it nothing happens and the URL shows the data that I wrote in the inputs but any message appears.