Jayprakash Jayprakash - 3 months ago 6x
PHP Question

How to redirect to thankyou.html page (PHP)

I am trying to redirect to thankyou.html after the mail has been sent but i failed to do.

I have used header option but it was not working with me.
may be i have done something wrong.
when someone submits this query the page should go to thankyou.html, i have already made this page.

this is my php script



$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$treatment = $_POST['treatment'];
$gender = $_POST['gender'];
$date = date('y/m/d');
$message = $_POST['message'];

$to = 'enquiry@kbc.com' ;
$subject = 'Inquiry' ;

$query = "insert into inquiry
(name,email,phone,treatment,gender,date) values ('$name','$email','$phone','$treatment','$gender','$date')";

if(mysqli_query($db_conx, $query)){

echo "<script>alert('Thank you for submitting your query, our doctors will call you soon!')</script>";

mail ( $to, $subject,
"From:" . $name .
", Email: " . $email .
", Number: ". $phone .
", Gender: " . $gender.
", Treatment: " . $treatment.
", Message: " . $message );




You have two options here,

1) Either you can use:

header('Location: http://domain.com/thank-you.html');

2) Use javascript:


Moreover, You can post your mail data via Ajax and if data is successfully posted, you can redirect :)