Launch Modal Window

Asked

Viewed 54 times

0

I’m trying to launch a window after sending email and then kill the session and then redirect to the index page.

// Enviar email
$mail->Send();

//echo "E-mail enviado com sucesso!";
echo "<script>alert('O boleto foi enviado para o e-mail informado!');</script>"; 
//destruir a sessão e redirecionar para a pagina principal
session_destroy(); 
header("Location: index.php");

}
catch (phpmailerException $e) {
// Mensagens de erro do PHPMailer
echo $e->errorMessage();
}
catch (Exception $e) {
// Outras mensagens de erro
echo $e->getMessage();

}

This line is not being called, it’s going straight to echo "<script>alert('O boleto foi enviado para o e-mail informado!');</script>"; How to solve?

Remainder of the code

// Realizando o envio do email
try {
    // Remetente
    $mail->AddReplyTo('[email protected]', 'Meu Nome');
    $mail->SetFrom('[email protected]', 'Meu Nome');

    // Destinatário
    $mail->AddAddress($email_cli, $cliente);

    // Assunto
    $mail->Subject = 'Boleto de Pagamento';

    // Mensagem para clientes de email sem suporte a HTML
    $mail->AltBody = 'Olá '.$cliente . " segue em anexo o boleto para o pagamento do seu pedido";

    // Mensagem para clientes de email com suporte a HTML
    $mail->MsgHTML('<p>Olá ' . $cliente . ' ! Obrigado pela preferência! 
    <br> Segue em anexo o boleto para o pagamento.</p>');

    // Adicionar anexo
    $caminho = 'pdf/tmp/';
    $ficheiro = $arquivo;

    $mail->AddAttachment($caminho.$ficheiro);

    // Enviar email
    $mail->Send();

    //echo "E-mail enviado com sucesso!";
    >>>Aqui preciso da mensagem e depois destruir a sessão e redirecionar para index.
} catch (phpmailerException $e) {
    // Mensagens de erro do PHPMailer
    echo $e->errorMessage();
} catch (Exception $e) {
    // Outras mensagens de erro
    echo $e->getMessage();
}

1 answer

2


What must be happening is the fact that the header() is a head instruction for the browser, and it ends up ignoring alert().

You could try redirecting by Javascript by writing this text:

<SCRIPT type='text/javascript'> 
    alert('O boleto foi enviado para o e-mail informado!');
    window.location.replace(\"index.php\");
</SCRIPT>
  • Unfortunately, it didn’t work... keep going straight through...

  • @Xavier could put the interim code? I believe the code starts at a try Right? Try to do an echo before and an echo after the try/catch. Also remove the header() if you haven’t already.

  • Beauty Rodrigo. It worked like this: <? php $refresh = '<meta http-equiv="refresh" content="1; url=index.php" />'; echo('<script type="text/javascript">Alert("The ticket was sent to the email!")</script>'); session_destroy(); Exit ($refresh); } So it worked. This way is wrong?

  • If this form is not wrong, have to center this message window in the form?

  • I think it’s not wrong. Since Voce has already destroyed Session, the user will have no way to do anything wrong. Centralize the browser Alert you say?

  • Yes. Center on the screen!!

  • @Xavier I’m sorry, but I asked more because I believe that there is no way to change the look of an Alert. This is something from the browser. If you want something different you will have to make echo output an html with an same layout or use another layout for you.

  • Thanks for the help Dobrychtop and Rodrigo.

Show 3 more comments

Browser other questions tagged

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