2013-05-04 40 views
0

我終於得到我的表格信息發送到我的電子郵件,但我仍然有我的表格網頁的問題。當我點擊提交按鈕時,瀏覽器不會刷新頁面,而是轉到我的php.file中,在其中顯示黑色頁面。我試圖將頁面重新指向表單網頁(不使用java腳本)。如何在提交信息後重定向我的表單?

這裏是我到目前爲止的代碼,包括PHP文件:

<form method="post" action="PHP_Email_Form.php"> 
          <p style="font-family:Arial, Helvetica, sans-serif; color:#FFF; font-size:12px; 
          font-weight:bold"><label>First Name: 
           <input type="text" name="First Name" size="30" maxlength="30" 
           style="margin-left:27px" /> 
          </label></p> 
          <p style="font-family:Arial, Helvetica, sans-serif; color:#FFF; font-size:12px; 
          font-weight:bold"><label>Last Name: 
           <input type="text" name="Last Name" size="30" maxlength="30" 
           style="margin-left:27px" /> 
          </label></p> 
          <p style="font-family:Arial, Helvetica, sans-serif; color:#FFF; font-size:12px; 
          font-weight:bold"><label>Phone Number: 
           <input type="text" name="Phone Number" size="30" maxlength="10" 
           style="margin-left:5px" /> 
          </label></p> 
          <p style="font-family:Arial, Helvetica, sans-serif; color:#FFF; font-size:12px; 
          font-weight:bold"><label>Email: 
           <input type="text" name="Email" size="30" maxlength="30" 
           style="margin-left:59px" /> 
          </label></p> 
          <p style="margin-top:19px; margin-left:244px;"> 
           <input type="submit" value="submit" /> 
          </p> 

         </form> 

PHP文件:

<?php 
$to = '[email protected]'; 
$subject = 'test email form'; 
$message= ''; 
foreach ($_POST as $key => $value) 
{ 
    $message .= $key . ': ' . $value . PHP_EOL; 
} 
mail($to, $subject, $message); 
?> 

回答

0

你沒有輸出任何東西從你的PHP,所以你可以發送一個頭重定向。

<?php 

// ... send email 

header('Location: /backToMyForm.html'); 

?> 
+0

謝謝你......完美的工作! – DWalk 2013-05-05 06:31:11

0

使用PHP頭重定向您已成功發送的電子郵件後:

<?php 
... 
... 
mail($to, $subject, $message); 

header("Location: successmessage.php"); // Redirect browser 

/* Make sure that code below does not get executed when we redirect. */ 
exit; 

ref:http://php.net/manual/en/function.header.php