Page redirects and the contact form is not sent via email

Asked

Viewed 28 times

-1

The page is redirected, but the form is not sent. I believe "email.php" is not running.

I’ve tried several different features, the problem that this style framework and Java used in the project is a mix of modified bootstrap with other features. Who can help solve this problem I thank <3

<iframe style="display:none;" name="contato1" id="contato1" src="./php/email.php"></iframe>

    <form class="form-input-classic" action="./php/email.php" name="contato_form" id="contato_form" method="post"
 target="contato1" 

    onsubmit="alert('Olá, ' + nome.value +' sua mensagem foi enviada com sucesso!');

    window.location.href = 'https://Página que eu quero e está sendo redirecionada :)';

    return true;">
 


    <!--<div class="lp-section-video">
    <div class="lp-section-video-mockup" style="background-image: url(./img/secao/iphone3.png);">
    -->
        <fieldset style="background-color:#f7fbff;border-radius:30px;">
        
        <h2 style="text-align: center">Contato</h2>

        <label for="nome">Nome</label>

        <input type="text" id="nomeid" placeholder="Digite seu nome" required="required" name="nome" />
        <br>

        <label for="fone">Telefone</label>

        <input type="tel" id="foneid" placeholder="(xx)x-xxxx-xxxx" name="telefone" required="required" />
        <label for="email">Email</label>

        <input type="email" id="emailid" placeholder="[email protected]" name="email" required="" />

        <br><br>

        <textarea  minlength="30" id="textareaid" name="mensagem" placeholder="Escreva sua mensagem aqui."
 cols="90" rows="8" style="resize:none";></textarea>
        <br><br>

        <div class="form-submit-classic">

        <input type="submit" class="form-submit-classic" id="enviar" value="Enviar" data-ref="button-sib">
        </div>
        </fieldset>
    </form>
                        

The Code in php is this: Note: I changed the email addresses and site name for privacy.

<?php 


if(isset($_POST['submit'])){

    $nome= addslashes($_POST['nome']);
    $telefone = addslashes($_POST['telefone']);
    $email = addslashes($_POST['email']);
    $mensagem = addslashes($_POST['mensagem']);

    $to = "meuemaildecontato";
    $subject = "Contato - NomedoMeuSite";

    $body = "Nome: ".$nome. "\r\n".
            "Telefone: ".$telefone. "\r\n".
            "Email: ".$email. "\r\n".
            "Mensagem: ".$mensagem;

    $header = "From: emaildeenvio"."\r\n".
                "Reply-To:".$email."\r\n".
                "X=Mailer:PHP/" .phpversion();

    mail($to,$subject,$body,$header);


/*if(mail($to,$subject,$body,$header)){

        echo(
            'Sua Mensagem foi enviada com sucesso!'
        #<script> 
            #alert('Olá, ' + nome.value +' sua mensagem foi enviada com sucesso!');
window.location.href = 'https://Sitequeeugostariade redirecionar';
        #   </script>

        );


    }else{

        echo(
            'Sua mensagem não foi enviada, tente novamente mais tarde.'
            #<script> 
            #alert('Olá, ' + nome.value +' sua mensagem não foi enviada, tente novamente mais tarde.');
            #</script>
        );
    }
*/

}


?>

  • 1

    Most likely your email.php file is not running because there is no field with the name "Submit" being sent from the form to it. test put before if a var_dump($_POST);die; to see if it exists

  • Julyano God bless you immensely, I love you dearly! KKKKKKKKKKKKKK I BROKE MY HEAD 2 DAYS AGO

1 answer

0

The Event listeners are executed before the action. The logic of this is that the action is already executed outside the page and when executing the Event listeners before allows the javascript to decide whether or not to execute the action (with Return true or false).

Therefore, the reason email is never sent is that javascript itself redirects to another page before executing the action.

To resolve the problem, remove your onsubmit and put the redirect logic in php.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.