2013-02-15 38 views
0

我有一個表單觸發提交的電子郵件,但我想重定向到提交不同的頁面。電子郵件沒有觸發重定向到頁面

<form id="customisesystem" name="enquiry" onsubmit="return formCheck(this);" method="POST" action="<?php echo the_permalink(); ?>"> 

我想這個更改爲以下:

<form id="customisesystem" name="enquiry" onsubmit="return formCheck(this);" method="POST" action="<?php bloginfo('url'); ?>/thank-you"> 

然而,這沒有按」

目前的電子郵件只有滿足以下(即重新加載相同頁面)來通過觸發電子郵件。

任何人都可以看到出了什麼問題?

這是發送電子郵件的腳本。

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

$to = "[email protected]"; 
$header = 'From: [email protected]'; 
$subject = "Quotation"; 
$enquiry_first_name = $_POST['enquiryfirstname']; 
$enquiry_last_name = $_POST['enquirylastname']; 
$enquiry_title = $_POST['enquirytitle']; 
$enquiry_organisation = $_POST['enquiryorganisation']; 
$enquiry_address = $_POST['enquiryaddress']; 
$enquiry_country = $_POST['enquirycountry']; 
$enquiry_email_address = $_POST['enquiryemailaddress']; 
$enquiry_telephone = $_POST['enquirytelephone']; 
$enquiry_additional_comments = $_POST['enquiryadditionalcomments']; 
$enquiry_product = get_the_title(); 
if(!empty($_POST['hardware'])) { 
    foreach($_POST['hardware'] as $check) { 
     $hardwareresults .= $check."\n"; 
    } 
} 
if(!empty($_POST['systems'])) { 
    foreach($_POST['systems'] as $check) { 
     $systemsresults .= $check."\n"; 
    } 
} 
$productresults = ""; 
$quantities = array_combine($_POST['product'], $_POST['quantity']); 
foreach ($quantities as $product => $quantity) { 
    if ($quantity > 0) { 
     $productresults .= "$quantity x $product \n"; 
    } 
} 


$body = "You have a quote request from the website: 

Name: $enquiry_title $enquiry_first_name $enquiry_last_name 
Type of organisation: $enquiry_organisation 
Address: $enquiry_address, $enquiry_country 
E-Mail: $enquiry_email_address 
Tel: $enquiry_telephone 
Comments: $enquiry_additional_comments 

Send more information on: 
$systemsresults 

Quotation: 
$enquiry_product 

Hardware: 
$hardwareresults 

Accessories: 
$productresults 

Kind regards"; 

mail($to, $subject, $body, $header); 

echo "Thank you for your enquiry."; 

} ?> 
+0

顯示你的js動作(formCheck)請 – 2013-02-15 11:14:19

+0

你在哪裏發送php代碼發送謝謝頁面或者同一個表單頁面 – anstrangel0ver 2013-02-15 11:17:02

回答

2

繼續使用其發送電子郵件

,並在那裏你已經使用回聲"Thank you for your enquiry.";

header('location: ' . bloginfo('url') . '/thank-you'); 

編輯

要獲得發佈的數據裏面感謝頁面替換它的電子郵件代碼後<?php echo the_permalink(); ?>,你應該從郵件頁面傳遞這些數據。

有2種方式,你可以在這種情況下

  1. 使用get方法發送其他頁面上的數據。 `/謝客/?名稱= ABC &年齡= XYZ
  2. 存儲在會話中的值,並訪問這些會話頁面上

編輯

嘗試是這樣的

header('location: http://www.yourblog.com/thank-you/?title=' . $enquiry_title); 

,並感謝您頁,把它變成一個變量,然後在你想要顯示它的地方回顯那個變量。

<?php 
$title = $_GET['title']; 
... 
?> Thank you message and your HTML structure 
Your message titled: <b> <?php echo $title; ?> </b> is received. we will contact you shortly 
.... blah blah 

我希望這是有道理的。

+0

它實際上並不是拾取'bloginfo('url')',語法錯誤?它只是讀感謝的一部分,重定向和發送作品。 – Rob 2013-02-15 13:29:21

+0

如果頁面在博客範圍之外意味着博客文件不包含在郵件php頁面中,那麼它將不會轉到bloginfo('url')。你需要在郵件頁面有一些網址 – 2013-02-15 14:36:47

+0

好吧,沒問題,我可以硬編碼。沒有辦法使用表單的動作嗎?感謝頁面有一些東西依賴於發佈數據,這些數據不再適用於您的方法。 – Rob 2013-02-15 14:40:55

0

這很正常,因爲您不會發送任何信息到您的電子郵件腳本。要在發送電子郵件後將客戶端重定向到其他頁面,您必須將propper HTTP標頭髮送給用戶代理。 您可以通過將此代碼添加到您的電子郵件腳本的最後一行做到這一點(不改變行動提交表單):

header ("Location: " . bloginfo('url') . "/thank-you"); 

這將用戶重定向到另一個頁面後,郵件發送過程結束。

編輯

由於「阿米爾馬哈茂德」已經提到的,你可以在URL查詢字符串像這樣通過標題:

header ("Location: http://some.site.com/foo/bar/thank-you/?title=$enquery_title"); 

,並感謝頁面只是這樣做:

$title = $_GET["title"]; 
# use $title as you need 

我跳這有助於

+0

這實際上並不是拾取'bloginfo('url')',語法錯誤?它只是讀感謝的一部分,重定向和發送作品。 – Rob 2013-02-15 13:29:39

相關問題