HTML code:
<section class="contato">
<div class="parallax-targetaf section-0" data-parallax="scroll" data-image-src="img/4.jpeg">
<div class="container cf">
<div class="containerrr">
<form id="contact" action="mail_send.php" method="post">
<h3>Precisa de Ajuda?</h3>
<h4>Entraremos em contato em 24 horas úteis.</h4>
<fieldset>
<input required placeholder="Digite seu nome" type="text" name="nome" >
</fieldset>
<fieldset>
<input required placeholder="Digite seu email" type="email" name="email">
</fieldset>
<fieldset>
<input required placeholder="Deixe o seu numero (Opicional)" type="text" name="telefone">
</fieldset>
<fieldset>
<textarea required placeholder="Digite sua mensagem ...." name="mensagem"></textarea>
</fieldset>
<fieldset>
<button name="BTEnvia" type="submit" id="contact-submit" data-submit="...Enviando">Enviar</button>
</fieldset>
</form>
</div>
</div>
</div>
</section>
php code:
<?php
function pegaValor($valor) {
return isset($_POST[$valor]) ? $_POST[$valor] : '';
}
function validaEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
function enviaEmail ($nome, $de, $telefone, $msg , $para, $email_servidor) {
$headers = "From: $email_servidor\r\n" .
"Reply-To: $de\r\n" .
"X-Mailer: PHP/" . phpversion() . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($para, $assunto, nl2br($mensagem), $headers);
}
$email_servidor = "[email protected]";
$para = "[email protected]";
$nome = pegaValor("nome");
$de = pegaValor("email");
$telefone = pegaValor("telefone");
$msg = pegaValor("mensagem");
if (validaEmail($de) && $mensagem) {
enviaEmail($nome, $de, $telefone, $msg , $para, $email_servidor);
$pagina = "mail_ok.php";
} else {
$pagina = "mail_error.php";
}
header("location:$pagina");
?>
I tested it on my local host and it just goes to page mail_error.php I do not know why anyone could help me where I'm wrong?
And if you have someone to add an example of clicking on "SEND", instead of opening a page an "alert" appears in js or ajax. (Email sent successfully or error) ..