Show Alert or message after a header? PHP


I was creating an insert , and when sending the data I got an alert message saying that the data had been inserted successfully, but now, the page goes blank and only shows that alert.

What I did so that it would not stay stuck was redirect again with header , only this time I do not get the message or the alert.

It's very simple I guess, I put it before and after the header and it didn't work.

if ($mail->send()) 


  echo '<p class="alert alert-success agileits" role="alert">Captura realizada correctamente!p>';

  } else {

  echo "Mailer Error: " . $mail->ErrorInfo;


to print an alert inside php do it like this:

     echo "<script>
                window.location= 'url.php'
Scroll to Top