I need help when the email is successfully sent a message appears in an alert (it can be another way), saying that it was sent successfully, so that user n has doubts about whether it was or not. Here is the code I have:
HTML
<form id="formulario" name="formulario" action="mail.php" method="post">
<div class="form-group">
<input type="name" name="name" class="form-control mt-2" placeholder="Nome" autocomplete="off" required>
<input type="email" name="email" class="form-control mt-2" placeholder="[email protected]" autocomplete="off" required>
<textarea class="form-control mt-2" name="message" rows="8" placeholder="Escreva aqui..." required></textarea>
<input type="submit" class="btn btn-lg btn-block mt-3 enviar-b" Enviar>
</div>
</form>
JS
<script language="JavaScript">
var frmvalidator = new Validator("formulario");
frmvalidator.addValidation("name","req","Porfavor preencha seu nome");
frmvalidator.addValidation("email","req","Porfavor preencha seu email");
frmvalidator.addValidation("email","email",
"Email Inválido");
PHP
<?php header('Content-Type: text/html; charset=utf-8');
$errors = '';
$myemail = '[email protected]';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Erro: Todos os campos são requeridos";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Erro: Email Inválido";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Formulário de Contato: $name";
$email_body = "Você recebeu uma nova mensagem. ".
"Aqui estão os detalhes:\n Nome: $name \n ".
"Email: $email_address\n Menssagem: \n $message";
$headers = "Para: $myemail\n";
$headers .= "De: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: index.html');}
?>