PHP标头没有重定向到感谢页面

时间:2016-01-25 16:24:14

标签: php forms head submission

不知道为什么最后的标题没有重定向到thankyou.html页面。 我读过类似的以前的帖子,但在大多数情况下,人们只是使用echo()而不是header()或类似的东西。

<?php  
if(isset($_POST['submit']))
{

$email_us = "info@pureazorestours.com";
$email_user = $_POST['email'];

$subject_us = "Website Reservation";
$subject_user = "Reservation request recieved";

$fname = $_POST['fname'];

$msg_us = '
<html>
<head>
<title>Website Reservation</title>
</head>
<body>
<p>RESERVATION DETAILS:</p>
<table>
    <tr>
        <td>Name:</td>
        <td>'.htmlspecialchars($fname).'</td>
    </tr>
    <tr>
        <td>Email:</td>
        <td>'.htmlspecialchars($_POST['email']).'</td>
    </tr>
    <tr>
        <td>Tour:</td>
        <td>'.htmlspecialchars($_POST['tname']).'</td>
    </tr>
    <tr>
        <td>Reservation Date:</td>
        <td>'.htmlspecialchars($_POST['datetour']).'</td>
    </tr>
    <tr>
        <td>Group Size:</td>
        <td>'.htmlspecialchars($_POST['groupsize']).'</td>
    </tr>
    <tr>
        <td>Pick-up Accommodation:</td>
        <td>'.htmlspecialchars($_POST['fpickup']).'</td>
    </tr>
    <tr>
        <td>Optional Message:</td>
        <td>'.htmlspecialchars($_POST['feedback']).'</td>
    </tr>
</table>
</body>
</html>
';

$msg_user = '
<html>
<head>
<title>Pure Azores Tours Reservation Request</title>
</head>
<body>
<p>Dear '.htmlspecialchars($fname).'</p>
<p>Thank you for submitting a reservation with Pure Azores Tours!
<p>Please expect an email from us confirming your reservation within the         next few hours. 
We usually respond in a few minutes!

<p>RESERVATION DETAILS:</p>
<table>
    <tr>
        <td>Name:</td>
        <td>'.htmlspecialchars($fname).'</td>
    </tr>
    <tr>
        <td>Email:</td>
        <td>'.htmlspecialchars($_POST['email']).'</td>
    </tr>
    <tr>
        <td>Tour:</td>
        <td>'.htmlspecialchars($_POST['tname']).'</td>
    </tr>
    <tr>
        <td>Reservation Date:</td>
        <td>'.htmlspecialchars($_POST['datetour']).'</td>
    </tr>
    <tr>
        <td>Group Size:</td>
        <td>'.htmlspecialchars($_POST['groupsize']).'</td>
    </tr>
    <tr>
        <td>Pick-up Accommodation:</td>
        <td>'.htmlspecialchars($_POST['fpickup']).'</td>
    </tr>
    <tr>
        <td>Optional Message:</td>
        <td>'.htmlspecialchars($_POST['feedback']).'</td>
    </tr>
</table>
</body>
</html>
';

$headers_us = "MIME-Version: 1.0" . "\r\n";
$headers_us .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers_user = "MIME-Version: 1.0" . "\r\n";
$headers_user .= "Content-type:text/html;charset=UTF-8" . "\r\n";

$headers_us .= 'From: <'.$_POST['email'].'>' . "\r\n";
$headers_user .= 'From: <info@pureazoretours.com>' . "\r\n";

mail($email_us,$subject_us,$msg_us,$headers_us);
mail($email_user,$subject_user,$msg_user,$headers_user);
header('Location: thankyou.html');
exit;
}
?>

编辑:HTML代码

    <div class="wrap-form">
    <form action="" method="post">

    <label>
         <span>Name:</span><input id="fname" type="text" placeholder="Your Name" name="fname" required />
    </label>
    <label>
        <span>Email:</span><input id="email" type="text" placeholder="Your Email" name="email" required />
    </label>
    <label> 
        <span>Tour</span>
        <select name="tname" required>
        <optgroup label="Day Tours">
            <option value="West São Miguel" <?php if($_GET['title'] == 'dt01'){ ?>selected="selected"<?php } ?>> - West São Miguel</option>
            <option value="A Day at Furnas Valley" <?php if($_GET['title'] == 'dt02'){ ?>selected="selected"<?php } ?>>  - A Day at Furnas Valley</option>
            <option value="Nordeste with Canyoning" <?php if($_GET['title'] == 'dt03'){ ?>selected="selected"<?php } ?>> - Nordeste with Canyoning</option>
        </optgroup>
        <optgroup label="Hiking Tours">
            <option value="Pico da Vara climb" <?php if($_GET['title'] == 'ht01'){ ?>selected="selected"<?php } ?>> - Pico da Vara Climb</option>
        </optgroup>
        <optgroup label="Multi-Day Packages">
            <option value="São Miguel Essential 2 days" <?php if($_GET['title'] == 'pa01'){ ?>selected="selected"<?php } ?>> - São Miguel Essential 2 days</option>
        </optgroup>

        </select>
    </label>

    <table>
            <tr>
                <td>
                    <label>
                    <span>Tour Date:</span><input style="width:130px" id="datepicker" type="text" name="datetour" required readonly/>
                    </label>
                </td>
                <td style="text-align: right">
                    <label>
                    <span>Group Size:</span><input style="width:56px; text-align:center" id="groupsize" type="number" name="groupsize" min="1" required value="2" />
                    </label>
                </td>
            </tr>
    </table>
    <label>
        <span class="clear">Pick-up accommodation:</span>
        <input id="fpickup" type="text" placeholder="Your Accommodation" name="fpickup" />
    </label>
    <label>
        <span>Message</span>
        <textarea id="feedback" placeholder="(Optional Text)" name="feedback"></textarea>
        <input type="submit" name="submit" id="submit" value="Submit" required/>
    </label>

    </form>
</div>

1 个答案:

答案 0 :(得分:1)

这里有两个常见问题。首先,您可能在header()函数之前输出。这可以是PHP代码之前的任何空格或HTML。你不能有任何输出到页面,甚至一个空格,否则PHP会给你一个已发送的标题&#39;信息。 Jay指出,你应该打开错误报告。

其次,检查thankyou.html文件实际存在,并且与上面的文件完全相同,文件名和扩展名完全相同。