发送邮件后,我试图重定向到thankyou.html,但是我做不到。
我使用了标头选项,但它不能与我一起使用。
可能是我做错了什么。
当有人提交此查询时,页面应转到thankyou.html,我已经创建了此页面。
这是我的PHP脚本
<?php
include("connect.php");
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$treatment = $_POST['treatment'];
$gender = $_POST['gender'];
$date = date('y/m/d');
$message = $_POST['message'];
$to = '[email protected]' ;
$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 );
}
?>
最佳答案
您有两个选择
1)您可以使用:
header('Location: http://domain.com/thank-you.html');
2)使用javascript:
window.location.href='http://domain.com/thankyou.html';
此外,
您可以通过Ajax发布邮件数据,如果数据成功发布,则可以重定向:)
关于javascript - 如何重定向到thankyou.html页面(PHP),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37952443/