我正在爲我的一個客戶做一些網絡開發,並且遇到了障礙。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