2011-12-05 76 views
0

我有一個Html站點。在那裏有每個頁面發送郵件的形式。表單操作是在另一個頁面是process.php page.I要重定向從PHP頁面到HTML發送郵件後的頁面。 這是我的html代碼Php重定向到父頁面

<form name="mail" id="mail" method="post" action="process.php" onSubmit="return valid_form();"> 
    <div class="form_bg11"> 
    <div class="free_call_back">Free Callback Request</div> 
    <input name="txtname" id="txtname" type="text" class="free_cal_field" value="Your Name" onClick="(this.value='')" > 
    <input name="txtphone" id="txtphone" type="text" class="free_cal_field" value="Your Phone Number" onClick="(this.value='')"> 
    <input type="submit" name="Submit" style="background-image: url('images/submit.png'); border: 0px none; height: 19px; margin-left: 85px; width: 56px; margin-top:5px;" value=" "> 
    </div> 
    </form> 

氏是我process.php頁

<?php 
if(isset($_POST['Submit'])) 
{ 
    $name = $_POST['txtname']; 
    $phone = $_POST['txtphone']; 

    $to = "[email protected]"; 
    $subject = "New Request Come !"; 
    $message = '<div style="background-color: #EEEEEE;border-bottom: 1px solid #DCDCDC;padding: 10px 0 20px;width: 400px;"> 
<div style="width:400px;"> 

<div style="width:400px;background-color:#eeeeee;padding: 10px 0 20px;border-bottom:1px solid #dcdcdc;"> 
<div style="width:300px; text-align:center;color:#666666;margin-left:20px;font-size:12px;font-weight:bold;"> 
Now you got a new request from : 
</div> 
</div> <!--end of div_form_main--> 
<div style="width:400px;background-color:#eeeeee;padding: 10px 0 20px;border-bottom:1px solid #dcdcdc;"> 
<div style="float:left;width:150px;color:#666666;margin-left:20px;font-size:12px;font-weight:bold;"> Name:</div> 
<div style="float:left;width:auto;color:#000000;font-size:12px;font-weight:bold;">'.$name.'</div> 
</div> <!--end of div_form_main--> 
<!--end of div_form_main--> 
<div style="width:400px;background-color:#eeeeee;padding: 10px 0 20px;border-bottom:1px solid #dcdcdc;"> 
<div style="float:left;width:150px;color:#666666;margin-left:20px;font-size:12px;font-weight:bold;"> Phone Number:</div> 
<div style="float:left;width:auto;color:#000000;font-size:12px;font-weight:bold;">'.$phone.'</div></div> <!--end of div_form_main--> 
</div> <!--end of div_password_main-->'; 
    $headers = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
    $headers .="Content-Transfer-Encoding: 8bit"; 
    if(!mail($to, $subject, $message, $headers)) 
    { 
     $msg = "Sending mail is failed !"; 
    } 
    else 
    { 
     $msg = "Mail send Successfully !"; 
    } 
    print "<script type=\"text/javascript\">"; 
    print "alert('".$msg."')"; 
    print "</script>"; 
} 
?> 

我怎麼能做到這一點?

+0

標題( 「位置:__URL__」);會做的伎倆。確保沒有輸出發送到瀏覽器之前 – galchen

回答

0

我對你的措辭有些困惑。爲什麼你不能只使用PHP header()函數?

header('Location: http://www.example.com/'); 
+0

通過使用這我不能去相應的html頁面。 process.php對於所有的html頁面都是通用的。因此,寫這個「header('Location:http://www.example.com/');」只重定向到網站的索引頁面而不是相應的html頁面 – Kichu

+0

您如何使用'process.php'?你有沒有想過AJAX? – Blender

+0

我知道這個的阿賈克斯 – Kichu

0

快速寫了

if(!mail($to, $subject, $message, $headers)) 
     { 
      $msg = "Sending mail is failed !"; 

     } 
     else 
     { 
      $msg = "Mail send Successfully !"; 
print "<script type=\"text/javascript\">"; 
     print "window.location.href= 'www.example.com' "; 
     print "</script>"; 

} 
     print "<script type=\"text/javascript\">"; 
     print "alert('".$msg."')"; 
     print "</script>"; 
+0

我們希望你不要在SO上使用簽名。您的個人簡介生物部分可以包含鏈接 – Blender

+0

對不起,我沒有太多的想法,請認真指導我, –

0

您可以修改procss.php(在你的JavaScript塊)

print "<script type=\"text/javascript\">"; 
print "alert('".$msg."')"; 
print "window.location.href='http://www.yourdomain/yourhtmlpage.html'"; 
print "</script>"; 
+1

嘿你不認爲,即使消息失敗後,它會重定向 –