I'm a beginner when it comes to PHP.
This is a 'contact us' form where users can send their questions. Currently, it's successful in sending submitted questions directly to our email. However, it failed to redirect to a thank you page after the submission. I sincerely hope that someone could help me. I'm lost. The codes are below. Thank you in advance.
<?php
// Define some constants
define( "RECIPIENT_NAME", "Choice Baby Enquiry" );
define( "RECIPIENT_EMAIL", "enquiry@choicebaby.com.my" );
// Read the form values
$success = false;
$senderName = isset( $_POST['name'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['name'] ) : "";
$senderEmail = isset( $_POST['email'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email'] ) : "";
$subject = isset( $_POST['subject'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['subject'] ) : "Enquiry";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";
// If all values exist, send the email
if ( $senderName && $senderEmail && $message ) {
$recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
$headers = "From: " . $senderName . " <" . $senderEmail . ">";
$success = mail( $recipient, $subject, $message, $headers );
}
if ( mail( $recipient, $subject, $message, $headers )) {
header ("Location: thanks.html");
exit ();
}
?>
----EDIT----
Here is the HTML :
<section class="contact_us_container">
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="text-align:center;"> <!-- section title -->
<h2>Get In Touch With Us</h2>
<p>Type your question here and we will get back to you as soon as possible.</p>
</div> <!-- End section title -->
<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12 form_holder"> <!-- form holder -->
<form action="includes/sendemail.php" class="contact-form">
<input class="form-control name" type="text" name="name" placeholder="Your Name">
<input class="form-control email" type="email" name="email" placeholder="Your Email">
<input class="form-control" type="text" name="subject" placeholder="Subject">
<textarea name="message" placeholder="Your Message"></textarea>
<button type="submit" class="submit">submit now<i class="fa fa-arrow-circle-right"></i></button>
</form> <!-- End form holder -->
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 pull-right address">
<address>
<div class="icon_holder float_left"><span class="icon icon-Pointer"></span></div>
<div class="address_holder float_left">M2-19-03,<br>8trium Tower, Jalan Cempaka SD 12/5,<br>Bandar Sri Damansara,52000 KL</div>
</address>
<address class="clear_fix">
<div class="icon_holder float_left"><span class="icon icon-Plaine"></span></div>
<div class="address_holder float_left">enquiry@choicebaby.com.my</div>
</address>
<address class="clear_fix">
<div class="icon_holder float_left"><span class="icon icon-Phone2"></span></div>
<div class="address_holder float_left">+ 603 6735 5374</div>
</address>
</div>
</div>
</div>
</section>