Check if the e-mail has already been sent

Asked

Viewed 135 times

1

I have the following functionality in my PHP code.

    // Envia o e-mail
    $enviado = $mail->Send();

    // Limpa os destinatários e os anexos
    $mail->ClearAllRecipients();
    $mail->ClearAttachments();


    if( $enviado ){
        return true;

    } else {
        return false;
    }   

Once the Submit on the page, fires an email using the above functionality, however if I give F5, another email is sent. I wonder if even if I updating the page (F5) I can send only one email ?

Thank you.

  • Take a look at Pattern PRG, it will probably help you. http://wordsideasandthings.blogspot.ca/2013/04/post-redirect-get-pattern-in-php.html

  • 1

    you can redirect the page in case of success and can replace that code by return $mail->Send();, then, outside the redirect function or not.

2 answers

1

  if( $enviado ){
      echo "<script>alert('E-mail enviado com sucesso!')</script>";
      header("Location: index.php");

        } else {
        echo "<script>alert('E-mail não foi enviado')</script>";
            header("Location: index.php");
        }  

0

Browser other questions tagged

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