A possible solution, which merges the proposals of the other answers, is to assemble a minimum HTML, but using a META to refresh it take a few seconds without disturbing ALERT:
<?php
mail($email,$assunto,$mens,$headers);
echo '<!DOCTYPE html>';
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo '<head>';
echo ' <meta http-equiv="refresh" content="5; url=http://example.com/index.php">';
echo '</head>';
echo '<body onload="alert('+"'"+'Email enviado com Sucesso!'+"'"+');">';
echo '<a href="http://example.com/index.php">click!</a>';
echo '</body>';
echo '</html>';
?>
You can remove the tag <a>
, but in these cases it is interesting to keep, so that in case there is a problem in the refresh, the user is not left without knowing what to do.
Now, I think MUCH better a simpler thing. Since it is to build an HTML, warn on the page itself:
<?php
mail($email,$assunto,$mens,$headers);
echo '<!DOCTYPE html>';
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo '<head>';
echo ' <meta http-equiv="refresh" content="10; url=http://example.com/index.php">';
echo '</head>';
echo '<body>';
echo '<p>Seu email foi enviado com sucesso.</p>';
echo '<a href="http://example.com/index.php">Prosseguir</a>';
echo '</body>';
echo '</html>';
?>
PHP runs on the server, JS Alert runs on the client. It would be nice to relida the basic concept of what is PHP, web server and internet browser, to facilitate the logic when doing the programming itself.
– Bacco