PHP标头未重定向到感谢页面
Posted
技术标签:
【中文标题】PHP标头未重定向到感谢页面【英文标题】:PHP header not redirecting to thank you page 【发布时间】:2016-01-25 16:24:14 【问题描述】:不知道为什么最后的标题没有重定向到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>
【问题讨论】:
在您打开<?php
标签error_reporting(E_ALL); ini_set('display_errors', 1);
后立即将错误报告添加到文件顶部
@JayBlanchard: 总是有最佳建议的人;)
99.9999% 的可能性是 ***.com/questions/8028957/… 的骗子。
【参考方案1】:
这里有两个常见问题。首先,您可能在 header()
函数之前有输出。这可以是 PHP 代码之前的任何空格或 HTML。你不能有任何输出到页面,甚至是一个空格,否则 PHP 会给你一个“标题已经发送”的消息。正如杰伊指出的那样,您应该打开错误报告。
其次,检查thankyou.html
文件是否真的存在,并且与上面的文件直接在同一个文件中,文件名和扩展名完全相同。
【讨论】:
我按照你们的建议做了。这是我收到的警告:无法修改标头信息 - 标头已由 /home/fy1jmqyz/public_html/pureazores.com/ 中的(输出开始于 /home/fy1jmqyz/public_html/pureazores.com/en/contact.php:124)发送第 347 行的 en/contact.php 我在此页面上有一些代码,它获取一个“标题”变量来更改下拉菜单上的预选。我想知道这是否是问题所在。我将使用 html 编辑 OP。 @MiguelSoares,谷歌优先:***.com/questions/8028957/…以上是关于PHP标头未重定向到感谢页面的主要内容,如果未能解决你的问题,请参考以下文章