我正在为我的一个客户做一些网络开发,并且遇到了障碍。PHP头(位置:)重定向需要指向以“http://”开头的网站吗?
**这里是发生了什么事情:**
- 我们有相同的联系表格上我们网站的多个副本,但我们希望每个,以便跟踪转换率完成后重定向到一个不同的着陆页。
- 在这个例子中,我正在处理about页面。当用户提交他们的请求以获取更多信息时,该页面将理想地重定向到唯一的感谢页面(例如,www.sample.com/thank-you-about.html);但是,事实并非如此。
- 电子邮件将完美发送,但重定向永远不会发生。没有错误抛出 - 没有。
在我告诉代码,这是我为了解决它在我自己已经试过:
-I've创建的窗体发送.PHP代码下的HTML代码体它的输入。据我所知,没有重定向正在发生,所以我显然还没有看到它。
- 我使用过“Header(Location:www.sample.com/thank-you-about.html)”,但那也没有做任何事。
- 我尝试过使用Javascript的“frame.location”方法,它似乎没有得到任何比PHP的尝试。
- 我已经将源页面和目标页面保存为.php页面,因为使用.html扩展名是问题的根源;同样的结果。
真的,我唯一能想到的是连接类型不满足Header()调用的要求。但是不会输出错误信息吗?
这里是有问题的接触形式:
<form id="contactForm" class="get-in-touch contact-form light" action="thank-you-about.php" method="post">
<input type="hidden" id="contact_nonce" name="contact_nonce" value="68592e213c"/><input type="hidden" name="" value="/"/>
<input type="hidden" name="contact-form-value" value="1"/>
<div class="iconic-input">
<input class="name" type="text" name="name" placeholder="Name*">
<i class="icons icon-user-1"></i>
</div>
<div class="iconic-input">
<input class="email" type="text" name="email" placeholder="Email*">
<i class="icons icon-email"></i>
</div>
<textarea class="msg" name="msg" placeholder="Message"></textarea>
<input type="submit" value="Send Message">
<div class="iconic-button">
<input type="reset" value="Clear">
<i class="icons icon-cancel-circle-1"></i>
</div>
</form>
下面是当前PHP文件,感谢任您about.php:
<?php
// Define some constants
define("RECIPIENT_NAME", "Sample");
define("RECIPIENT_EMAIL", "[email protected]");
define("EMAIL_SUBJECT", "New request from site sample webpage");
// Read the form values
$success = false;
$senderName = isset($_POST['name']) ? preg_replace("/[^\.\-\' a-zA-Z0-9]/", "", $_POST['name']) : "";
$senderEmail = isset($_POST['email']) ? preg_replace("/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email']) : "";
$message = isset($_POST['msg']) ? preg_replace("/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['msg']) : "";
$messageInterests = "";
$subject = "";
$currentURL = isset($_POST['current-URL'])? $_POST['current-URL'] : "";
//Parse checkboxes, include them in message body
$interestArray = $_POST['interest'];
if(!empty($interestArray)){
$messageInterests .= "INFORMATION OF INTEREST: ";
$N = count($interestArray);
for($i = 0; $i < $N; $i++)
{
$messageInterests .= "\r\n" . $interestArray[$i];
}
$subject .= $messageInterests . "\r\n \r\n";
}
else {
$subject = "GENERAL INQUIRY \r\n \r\n";
}
$subject .= $message;
$message = $subject;
// If all values exist, send the email
if ($senderName && $senderEmail && EMAIL_SUBJECT && $message) {
$recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
$headers = "From: " . $senderName . " <" . $senderEmail . ">";
mail($recipient, EMAIL_SUBJECT, $message, $headers);
header("Location: www.sample.com/thank-you-about.html"); /* Redirect browser */
}
?>
编辑::有人问之前,我知道没有复选框正在从这个特定的联系人表单解析。它们在我客户的服务页面上派上用场,而一般查询由关于页面,联系我们页面和主页处理。
SECOND EDIT ::所以,我修复了绝对的URL问题;但是,重定向问题仍然存在。谢谢大家,如此耐心!
没有比这更好的地方开始比手动http://php.net/manual/en/function.header.php –
没有通过'http://',它是作为一个相对URL处理,所以会正在寻找像'http:// example.com/www.sample.com/thank-you-about.html'这样的东西' –
在这种情况下,如果没有找到相对URL,是不是会输出错误或至少重定向到404页面? – user3579647