2013-10-10 60 views
0

我有一個簡單的聯繫表單,客戶將把他們的推薦,儘管提交表單時,我將它帶到流程頁面,這是很好的原因,謝謝你的頁面實現了。但提交後,它只是帶我到頁面的頁面,而不是感謝頁面。我無法找到問題,可以使用一些幫助,從你們窗體只輸出錯誤

形式:

<form action="includes/mail.php" method="post"> 
<table background="images/sequestrationreferral.jpg" height="408px" width="740px"> 
<tr> 
<td width="80px" height="50px"><label>Name:</label></td> 
<td><input class="input" type="text" name="name" width="225px" /></td> 
</tr> 
<tr> 
<td width="80px" height="50px"><label>Email Address:</label></td> 
<td><input class="input" type="text" name="email" width="225px" /></td> 
</tr> 
<tr> 
<td width="80px" height="120px"><label>Referals:</label></td> 
<td><textarea class="input" name="referals" cols="35" rows="5"></textarea><br /><br />Please use one per row?</td> 

</tr> 
<tr> 
<td></td> 
<td><input type="submit" name="submit" value="Send referals" class="btn" /></td> 
</table> 
</form> 

進程頁:

<? 
/* Edit these preferences to suit your needs */ 

    $mailto = '[email protected]'; // insert the email address you want the form sent to 
    $returnpage = '../thanks.php'; // insert the name of the page/location you want the user to be returned to 
    $sitename = '[Loanro]'; // insert the site name here, it will appear in the subject of your email 

/* Do not edit below this line unless you know what you're doing */ 

    $name = $_POST['name']; 
    $email = $_POST['email'] ; 
    $referals = stripslashes($_POST['referals']); 

    if (!$name) { 
     print("<strong>Error:</strong> Please provide your name.<br/><br/><a href='javascript:history.go(-1)'>Back</a>"); 
     exit; 
    } 
    if (!$email) { 
     print("<strong>Error:</strong> Please provide an email address.<br/><br/><a href='javascript:history.go(-1)'>Back</a>"); 
     exit; 
    } 
    if (!$referals) { 
     print("<strong>Error:</strong> Please provide your enquiry details.<br/><br/><a href='javascript:history.go(-1)'>Back</a>"); 
     exit; 
    } 
    if (!eregi("^[a-z0-9]+([-_\.]?[a-z0-9])[email protected][a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}", $email)){ 
    print("<strong>Error:</strong> this email address is not in a valid format.<br/><br/><a href='javascript:history.go(-1)'>Back</a>"); 
     exit; 
    } 

    $message = "\n$name submitted the following message:\n\n$enquiry\n\nTheir contact details are as follows:\n\nName: $name\nEmail Address: $email\n\n"; 

    mail($mailto, "$sitename Referal from $name", $message, "From: $email"); 
    header("Location: " . $returnpage); 
?> 

而且謝謝頁:

<article class="art-post art-article"> 


       <div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout layout-item-0"> 
    <div class="art-content-layout-row"> 

    </div> 
</div> 
<div class="art-content-layout-wrapper layout-item-4"> 
<div class="art-content-layout"> 
    <div class="art-content-layout-row"> 
    <div class="art-layout-cell layout-item-5" style="width: 75%" > 
<p>Thank you for contacting up, we will get back to you as soon as possible.</p> 


    </div> 
    </div> 
</div> 
</div> 
</div> 



</article> 
+0

嘗試包圍「ob_end_clean();」之前「標題()」 – tinybyte

+0

我認爲這個問題是因爲在進程頁面有問題,你在進程頁面中得到了什麼錯誤? – ncm

+0

如果是輸出錯誤,似乎沒有顯示謝謝頁面......但是你不應該在頭部之前顯示任何東西 – Brewal

回答

0

您的代碼看起來沒問題。 Location頭可能會失敗,因爲2個原因:

  1. 腳本yust做befor發送的報頭部分的輸出(可能是一個錯誤,或者befor你<?php
  2. Location頭應該是用戶簡單的一個看不見的標誌與絕對的URL,也許是你的相對路徑問題

你可以取代你的位置與頭:

$returnurl = "http://".$_SERVER["SERVER_NAME"] 
      . ($_SERVER["SERVER_PORT"]!=80?":".$_SERVER["SERVER_PORT"]:"") 
      . dirname($_SERVER["PHP_SELF"]) . "/" 
      . $returnpage; 
header("Location: " . $returnurl); 

而爲了讓成功和輸入錯誤之間的差別更好,你不需經過你的腳本改爲:

<? 
/* Edit these preferences to suit your needs */ 

    $mailto = '[email protected]'; // insert the email address you want the form sent to 
    $returnpage = '../thanks.php'; // insert the name of the page/location you want the user to be returned to 
    $sitename = '[Loanro]'; // insert the site name here, it will appear in the subject of your email 

/* Do not edit below this line unless you know what you're doing */ 

    $name = $_POST['name']; 
    $email = $_POST['email'] ; 
    $referals = stripslashes($_POST['referals']); 

    $errors = array(); 
    if (!$name)  $errors[] = "Please provide your name."; 
    if (!$email)  $errors[] = "Please provide an email address."; 
    if (!$referals) $errors[] = "Please provide your enquiry details."; 
    if (!eregi("^[a-z0-9]+([-_\.]?[a-z0-9])[email protected][a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}", $email)) { 
    $errors[] = "this email address is not in a valid format."; 
    } 

    if(count($errors) == 0) 
    { 
    $message = "\n$name submitted the following message:\n\n$enquiry\n\nTheir contact details are as follows:\n\nName: $name\nEmail Address: $email\n\n"; 

    mail($mailto, "$sitename Referal from $name", $message, "From: $email"); 
    $returnurl = "http://".$_SERVER["SERVER_NAME"] 
       . ($_SERVER["SERVER_PORT"]!=80?":".$_SERVER["SERVER_PORT"]:"") 
       . dirname($_SERVER["PHP_SELF"]) . "/" 
       . $returnpage; 
    header("Location: " . $returnurl); 
    } 
    else 
    { 
    echo "<strong>Errors:</strong>"; 
    echo "<ul><li>".implode("</li>\n<li>",$errors)."</li></ul>"; 
    echo "<a href='javascript:history.go(-1)'>Back</a>"; 
    } 
?> 

如果這仍然不起作用,停止使用地點的待辦事項:

readfile($returnpage); 

代替。

順便說一下,你的代碼示例不`噸看起來像全HTML網頁,他們應該至少有

<html> 
    <body> 
    // Your content 
    </body> 
</html> 
1

如果您的網絡服務器配置爲顯示警告(或者您可以啓用它們進行開發),請提供它們。

看來您的header()調用不起作用。通常情況下,如果在此調用之前您有任何類型的輸出。這可以是PHP腳本的開始<?標記之前的任何空格(空格,換行符等),或者它甚至可以是不可見的字符,如UTF-BOM。如果您使用Notepad ++之類的編輯器,則可以檢查文件是否以UTF編碼保存並確保其不含BOM。

+0

+1您指出會導致此類問題的很好的一點。 – ncm

1

php(即<?,?><?= 'something' ?>)標籤有時會產生問題。我總是把完整的PHP標籤(<?php ?><?php echo 'something' ?>

而且還最好是把ob_start();任何輸出前,ob_end_clean();重定向之前。

歡呼聲