A possible solution, which merges the proposals of the other answers, is to assemble a minimal HTML, but using a META for the refresh 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 <a>
tag, but in these cases it is interesting to keep, in case there is a problem in refresh , the user does not know what to do.
Now, I think MUCH better a simpler thing. Since it is to create an HTML, please notify 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>';
?>