How to create a form with ajax that when pressing the send button it will not redirect you to another page but a message just below "Sent data".
Here is an example of a code I'm studying, but it redirects you to another page in the sendemail.php case.
index.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form name="contactform" method="post" action="sendemail.php">
Nome: <input type="text" name="nome" /> </br>
E-mail: <input type="text" name="email" /> </br>
Assunto: <input type="text" name="assunto" /> </br>
Menssagem: <textarea name="menssagem"></textarea>
<input type="submit" value="Enviar Menssagem" />
</form>
</body>
</html>
sendemail.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$nome = $_POST['nome'];
$email = $_POST['email'];
$assunto = $_POST['assunto'];
$menssagem = $_POST['menssagem'];
?>
<?php
$to = "[email protected]";
$subject = "$assunto";
$menssagem = "<strong>Nome:</strong> $nome<br /><br /><strong>E-mail:</strong>$email<br /><br /><strong>Assunto:</strong> $assunto<br /><br /><strong>Menssagem:</strong> $menssagem ";
$header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/html; charset=iso-8859-1\n";
$header .= "From: $email\n";
mail($to, $subject, $menssagem,$header);
echo "Enviado!";
?>
</body>
</html>