I want to display a thanks message when mail is send with PHP
I tried something like
if(mail){echo "<script type='text/javascript'>alert('bedankt!');</script>";}
But I can't get the alert. I direct my form to mail.php but when the mail.php is done it redirects again to index.html with header('Location: ' . $_SERVER['HTTP_REFERER']);
Can this be the reason it doesn't show the alert? Or am I doing something wrong?
EDIT:
My code:
<form action="mail.php" method="post" onsubmit="bedanktBericht()">
<input class="invoeren" name="naamUser" type="text" placeholder="Naam" required>
<input class="invoeren" name="nummerUser" type="text" placeholder="Telefoonnummer" required>
<input class="invoeren" name="onderwerpUser" type="text" placeholder="Onderwerp" required>
<textarea class="invoeren" type="text" name="opmerkingUser" placeholder="Opmerking" required></textarea>
<button type="submit" id="contactButton" >Verstuur</button>
</form>
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
ob_start();
$naamUser = $_POST['naamUser'];
$nummerUser = $_POST['nummerUser'];
$onderwerpUser = $_POST['onderwerpUser'];
$opmerkingUser = $_POST['opmerkingUser'];
$formcontent="Aanvraag formulier Domein naam \n
Naam: $naamUser \n
Telefoonnummer: $nummerUser \n
Onderwerp: $onderwerpUser \n
Opmerking: $opmerkingUser \n
";
$recipient = "email@email.nl";
$subject = "Terug Bellen";
$mailheader = "From: \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header('Location: ' . $_SERVER['HTTP_REFERER']); /* Stuur de browser naar www.site.nl */
if(mail){echo "<script type='text/javascript'>alert('bedankt!');</script>";}
?>
UPDATE I want to execute the alert on the index.html page! Not mail.php! That's why I tried using the echo after the redirect.
Aucun commentaire:
Enregistrer un commentaire