This is a php file called sendmail.php that validates and sends an email from a contact form (which is included below)
The trouble I'm having is when the alert is clicked it redirects the page to sendemail.php because, I'm assuming, of form action=sendmail.php
How do I resolve this so it stays on the contact page and the user can pick up where they left off? I have tried using header like for the thank you page but to no avail!
if (isset($_POST["submit"])) {
$validate = validateInput($_POST["name"], $_POST["message"], $_POST["subject"]);
if ($validate==FALSE) {
$error_msg = "Please fill out all information";
echo '<script type="text/javascript">
alert("'.$error_msg.'");
</script>';
} else {
$mailcheck = spamcheck($_POST["email"]);
if ($mailcheck==FALSE) {
$error_msg = "Invalid email address";
echo '<script type="text/javascript">
alert("'.$error_msg.'");
</script>';
} else {
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$subject = $_REQUEST['subject'] ;
mail( "[email protected]", $subject, $message, "From: $email" );
header( "Location: http://www.thankyou.html" );
}
}
}
<form method="post" action="sendmail.php">
<input type="text" name="name" maxlength="50" placeholder="Name" class="contact-standard" /></br></br>
<input type="email" name="email" placeholder="Email" class="contact-standard"></input></br></br>
<input type="text" name="subject" placeholder="Subject" class="contact-standard"></input></br></br>
<textarea name="message" placeholder="Message" class="contact-message"></textarea></br></br>
<input type="submit" name="submit" value="Send Message" class="contact-submit"></input></br></br>
</form>
sendmail.phpover to this page (or include on submit).sendmail.phpafter success