-1

I have a form on my website, that is used to reset a users password. When the button is pressed, it calls this:

    if($getreq == 'true') {
      //Begynder: Sender mail til brugeren
      $headers = 'Content-type: text/html; charset=iso-8859-1';
      $headers = "MIME-Version: 1.0" . "\r\n";
      $headers = "Content-type:text/html;charset=UTF-8" . "\r\n";
      $headers = 'FROM: <BLANK>';
      $recipient = $getusermail;
      $subject = "Password reset";
      $message = "Password has been reset";
      mail($recipient, utf8_decode($subject), utf8_decode($message), $headers);
}

Everything works fine, but I would like some sort of message like "Sending..." or "Wait while sending mail" - just to notify the user that the browser is working (see image; https://i.stack.imgur.com/nd37W.png). Is this possible? I have tried google it, but havn't been able to find it (maybe I search the wrong words). I thought that I could just 'echo' before mail(), but the mail action always comes first.

<a class="button_link_small" href="edit.php?change=user&step=edit&postid=<?php echo $getPostID?>&ResetUserPass&req=true">Reset password</a>
if($getreq == 'true') {
      echo "Sending mail"
      //Begynder: Sender mail til brugeren

Can someone help me with a solution, and have in mind, that I need it guided out. :-) If more code shown is needed, just say.

MauiRiis
  • 21
  • 5
  • PHP does not *stream* the generated response back to the browser as it is generated, it is all sent at once, when the PHP script finishes. So you don't get your "sending" msg before the mail happens. You'll need to use Javascript to update the content of your browser while the PHP is running. The little icon your screenshot shows is sometimes called a spinner, try searches like "*php show spinner*" or "*php show progress*" you'll find many examples here and online about how to go about it. Here's one: https://stackoverflow.com/questions/18927533/show-loading-image-while-php-is-executing – Don't Panic Sep 08 '21 at 08:05
  • Does this answer your question? [Show loading image while PHP is executing](https://stackoverflow.com/questions/18927533/show-loading-image-while-php-is-executing) – Don't Panic Sep 08 '21 at 08:05
  • Thank, I will try new search :-) – MauiRiis Sep 08 '21 at 10:28
  • You should search on google like this "add loader while sending mail PHP", you will got multiple answers – Rajeev Singh Sep 13 '21 at 08:47

1 Answers1

0

Dude to 'Don't Panic answer I came up with this little work around:

if($getAction == 'ResetUserPass'){?>
<script type="text/javascript">
  var count = 5;
  var redirect = "edit.php?change=user&step=edit&postid=<?php echo $getPostID?>&req=true";
  function ResetCount(){
    var timer = document.getElementById("ResetCount");
    if(count > 0){
      count--;
      timer.innerHTML = "("+count+")";
      setTimeout("ResetCount()", 1000);
       }else{
            window.location.href = redirect;
      }
    }
</script>
<?php redtext("System is working, await green infobox...<span id=\"ResetCount\"><script type=\"text/javascript\">ResetCount();</script></span>");
}

if($getreq == 'true') {
    doing stuff... and..
    sending mail here...
    greentext("Bla bla bla, system is done.");
}

Prob not the best solution, but it works for me. :-)

MauiRiis
  • 21
  • 5