【问题标题】:How to redirect to thankyou.html page (PHP)如何重定向到thankyou.html页面(PHP)
【发布时间】:2016-10-23 11:24:27
【问题描述】:

我正在尝试在邮件发送后重定向到thankyou.html,但我失败了。

我使用了 header 选项,但它不适用于我。 可能是我做错了什么。 当有人提交这个查询页面应该去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    );



 }


 ?>

【问题讨论】:

标签: javascript php html phpmyadmin


【解决方案1】:

这里有两个选择,

1) 你可以使用:

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

2) 使用javascript:

window.location.href='http://domain.com/thankyou.html';

此外, 您可以通过 Ajax 发布您的邮件数据,如果数据成功发布,您可以重定向:)

【讨论】:

  • 嗨,先生,您能在我的代码中写标题选项吗
  • 您可以在echo "&lt;script&gt;alert('Thank you for submitting your query, our doctors will call you soon!')&lt;/script&gt;"; 之后使用,但是由于您已经在使用 javascript,因此 javascript 对您来说是更好的方法:)
【解决方案2】:

尝试使用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;
?>

【讨论】:

    猜你喜欢
    • 2011-03-20
    • 1970-01-01
    • 2012-01-02
    • 1970-01-01
    • 1970-01-01
    • 2011-06-26
    • 2010-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多