2017-02-21 65 views
0

我之前在另一個登陸頁面上使用了這個php代碼,並且無法更好地工作,但是現在我在託管在子域上的登錄頁面上使用它,並且它不工作。這兩個檔案的index.php和thank-you-page.html都存儲在同一個文件夾中。爲什麼這個PHP代碼重定向的形式不工作?

繼承人的代碼。

<div id="forma" class="col-2"> 
     <?php 
      $action=$_REQUEST['action']; 
      if ($action=="") 
      { 
      ?> 
     <form action="" method="POST" enctype="multipart/form-data"> 
     <input type="hidden" name="action" value="submit"> 
      <p>Nombre</p> <input type="text" name="name"/> 
      <p>Apellidos</p> <input type="text" name="surname"/> 
      <p>Email</p> <input type="text" name="email"> 
      <p>Tel&eacute;fono</p> <input type="text" name="phone" maxlength="12"/> 
      <input type="submit" value="Enviar" name="submit"/><input type="reset" value="Limpiar"> 
      <?php 
      include "include/thank-you-page.html"; 
      ?> 
     </form> 
     <?php 
     } 
     else if($_POST['email'] == '' or !preg_match("/^[a-zA-Z0-9_\.\-][email protected][a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/",$_POST['email'])){ 
     echo "Favor de ingresar un correo válido <a href=\"\">en la forma</a>";} 
     else 
     { 
     $name=utf8_decode($_POST['name']); 
     $surname=utf8_decode($_POST['surname']); 
     $email=$_POST['email']; 
     $phone=$_POST['phone']; 
     $message=" 
     APC Back-UPS Landing page: 
     Nombre: $name 
     Apellidos: $surname 
     e-mail: $email 
     telefono: $phone"; 
     if(($name=="")||($email=="")||($phone=="")) 

     { 
      echo "Favor de llenar los campos requeridos <a href=\"\">en la forma</a>"; 
     } 

     else 
     { 
     $from="From: $name<$email>\r\nReturn-path: $email"; 
     $subject = "Landing page Back-UPS"; 
     mail("[email protected]", $subject, $message, $from); 
     header('Location: http://www.securepowersolutions.com.mx/backups/thank-you-page.html'); 
      } 
     } 
     ?> 

有關爲什麼它不回答的任何想法?

+1

歡迎來到Stack Overflow!你能詳細說明你的代碼「不起作用」嗎?你在期待什麼,究竟發生了什麼?如果發生異常或錯誤,請發佈發生的行和詳細信息。請[編輯]這些細節或我們可能無法提供幫助。 –

回答

1

從文檔header

記住header()函數被髮送任何實際輸出之前,必須被調用,或者通過正常的HTML標記,在一個文件中的空行,或從PHP。使用include或require函數或其他文件訪問函數讀取代碼,並在調用header()之前輸出空格或空行是非常常見的錯誤。使用單個PHP/HTML文件時存在同樣的問題。

在調用標頭之前,您已經有HTML輸出。