我发邮件发送后我试图重定向到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 = '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 );
}
?>
答案 0 :(得分:2)
这里有两个选项,
1)您可以使用:
header('Location: http://domain.com/thank-you.html');
2)使用javascript:
window.location.href='http://domain.com/thankyou.html';
此外, 您可以通过Ajax发布邮件数据,如果数据成功发布,您可以重定向:)
答案 1 :(得分:0)
尝试使用header('Location: http://xxxxxxxx')
参考:http://php.net/manual/en/function.header.php
<?php
/* Redirect to a different page in the current directory that was requested */
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'mypage.php';
header("Location: http://$host$uri/$extra");
exit;
?>