submit button giving error - PHP

0

I'm putting a form in my index.php, to be sent the filled data to my email.

How do I do when the person clicks the submit button, the page does not update?

The system is working fine, it sends to my email correctly, but when I click the button to send, it appears that looks.

Doesanyoneknowwhyyouaregivingthiserror?

index.php

<?php$msg=0;@$msg=$_REQUEST['msg'];?><!DOCTYPEhtml><htmllang="pt-br">
<head> etc...

<body>
<form action="processaForm.php" method="post">
        <label for="nome">Nome:</label><br>
        <input id="nome" name="nome" type="text" required><br>
        <label for="email">E-mail: (obrigatório)</label><br>
        <input id="email" type="email" name="email" required><br>
        <label for="telefone"> Telefone/Whatsapp:</label><br>
        <input type="text" name="telefone" id="telefone" value="27 " required><br>
        <label for="assunto"> Descreva o serviço que deseja:</label><br>
        <textarea name="assunto" id="mensagens assunto"> </textarea><br>
        <input type="submit" id="miniSuccessAnimation" class="btn btn-success">
    </form>
</body>

PHP

<?php 
$para= "[email protected]";
$assunto= "Contato pelo Site";
$nome= $_REQUEST['nome'];
$fone= $_REQUEST['telefone'];
$email= $_REQUEST['email'];
$msg= $_REQUEST['assunto'];

    $corpo = "<strong> Mensagem de Contato</strong><br><br>";
    $corpo .= "<strong> Nome: </strong> $nome";
    $corpo .= "<br><strong> Telefone: </strong> $fone";
    $corpo .= "<br><strong> Email: </strong> $email";
    $corpo .= "<br><strong> Mensagem: </strong> $msg";

    $header = "Content-Type: text/html; charset= utf-8\n";
    $header .="From: $email Reply-to: $email\n";
mail($para,$assunto,$corpo,$header);
header("location:index.php?msg=enviado");
?>
    
asked by anonymous 17.11.2017 / 18:34

1 answer

2

Solution do not reload page (you need jQuery.js instantiated):

HTML

<form>
    <label for="nome">Nome:</label><br>
    <input id="nome" name="nome" type="text" required><br>
    <label for="email">E-mail: (obrigatório)</label><br>
    <input id="email" type="email" name="email" required><br>
    <label for="telefone"> Telefone/Whatsapp:</label><br>
    <input type="text" name="telefone" id="telefone" value="27 " required><br>
    <label for="assunto"> Descreva o serviço que deseja:</label><br>
    <textarea name="assunto" id="assunto"> </textarea><br>
    <input type="button" id="miniSuccessAnimation" class="btn btn-success">
</form>

JS

$(document).ready(function () {
    $("#miniSuccessAnimation").click(function () {
        var request = $.ajax({
            url: "processaForm.php",
            method: "POST",
            data: {nome: $("#nome").val(), email: $("#email").val(), telefone: $("#telefone").val(), assunto: $("#assunto").val()}
        });

        request.done(function (data) {
            alert(data);
        });

        request.fail(function () {
            alert("OPS ocorreu um erro na requisição.");
        });
    });
});

PHP

<?php 
$para= "[email protected]";
$assunto= "Contato pelo Site";
$nome= $_REQUEST['nome'];
$fone= $_REQUEST['telefone'];
$email= $_REQUEST['email'];
$msg= $_REQUEST['assunto'];

    $corpo = "<strong> Mensagem de Contato</strong><br><br>";
    $corpo .= "<strong> Nome: </strong> $nome";
    $corpo .= "<br><strong> Telefone: </strong> $fone";
    $corpo .= "<br><strong> Email: </strong> $email";
    $corpo .= "<br><strong> Mensagem: </strong> $msg";

    $header = "Content-Type: text/html; charset= utf-8\n";
    $header .="From: $email Reply-to: $email\n";
    if(mail($para,$assunto,$corpo,$header)){
        echo "E-Mail enviado";
    }else{
        echo "E-Mail não enviado";
    }

?>
    
17.11.2017 / 18:49