0
Guys, I need help when the email is sent successfully appear a message, in an Alert(may be another way), saying q was successfully sent , so the user has no doubts whether it was or n. Follow 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');}
?>