Successful Toast Dialogue on Submitting Form with PHP

1

I am creating a form for my personal website, where the user will fill in with first name, last name, email, password and message and this information will be sent to my personal email.

Sending the form is already working perfectly, with the PHP PHPMailer Lib.

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {

    echo "Enviado com sucesso!"
}

However, I would like instead of echo "Enviado com sucesso!" to display a message of success or failure with the Toast Framework Dialogue materialize.

    
asked by anonymous 26.09.2017 / 04:56

1 answer

1

It's quite simple, do it this way:

if (!$mail->send()) {
    echo "<script>
            $(function(){
                Materialize.toast('Mailer Error: ".$mail->ErrorInfo."' , 2200)
            }
            });  
    </script>";
} else {
    echo "<script>
            $(function(){
                Materialize.toast('Enviado com sucesso!' , 2200)
            }
            });  
    </script>";
}

Or

send-msg.php

if (!$mail->send()) {
    header("Location: pag_onde_vc_mostra_a_msg.php?acao=fail");
} else {
    header("Location: pag_onde_vc_mostra_a_msg.php?acao=ok");
}

pag_onde_vc_mostra_a_msg.php

if(isset($_GET['acao'])){
    $msg = "";
    if($_GET['acao'] == 'ok'){
        $msg = 'Mailer Error: ".$mail->ErrorInfo."';
    }
    if($_GET['acao'] == 'fail'){
        $msg = 'Enviado com sucesso!';
    }
    echo "  <script>
                $(function(){
                    Materialize.toast('".$msg."' , 2200)
                });  
            </script>";
}
    
26.09.2017 / 05:04