Show DIV by an ID

Asked

Viewed 53 times

0

I am wanting to add this message on a page called contact.php

<div class="alert alert-warning alert-dismissible" role="alert">
  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  <strong>Warning!</strong> Better check yourself, you're not looking too good.
</div>

This message should appear when the message is sent correctly via a page called send.php that is linked to Phpmailer. How do I get this file to show this message in contact.php when the message is sent correctly.

1 answer

1

On the page envia.php, after sending the email correctly create a session:

 /*----- Função PHPMailer ------*/
 $enviado = $mail->Send();

 if ($enviado) {
    $_SESSION['EmailEnviado']=1; /*Caso o e-mail seja enviado com sucesso*/
 } else {
    $_SESSION['EmailEnviado']=0;
 }

header("Location: contato.php"); /*redireciona para contato.php*/

On the page contato.php, at the beginning of the page before any HTML:

<?php 
    if (!isset($_SESSION)) session_start(); 
    if (!isset($_SESSION['EmailEnviado'])) { /*Verfica session do e-mail*/
      $_SESSION['EmailEnviado']=0;
    }
?>

In the message part check the email Session:

<?php if($_SESSION['EmailEnviado']==1){?> /*Mostra Mensagem caso e-mail enviado*/
    <div class="alert alert-warning alert-dismissible" role="alert">
      <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <strong>Warning!</strong> Better check yourself, you're not looking too good.
    </div>
 <?php }$_SESSION['EmailEnviado']=0;?> /*Reseta o valor da session*/

Browser other questions tagged

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