2013-06-22 19 views
0

我有一個聯繫表單的網頁投資組合,我一直在嘗試解決這個問題,但沒有成功。我不是PHP專家,所以我會盡力解釋。基本上我所擁有的是來自wordpress的聯繫人模板文件,我過去曾使用過,但我想要做的是(如果可能)在我的投資組合中實施。我的主要問題是,當我在瀏覽器中預覽我的網站時,它顯示了窗體上的PHP代碼。單頁網站聯繫表格的問題

<?php 
      if ($_SERVER['REQUEST_METHOD'] == "POST") { 
       // Check fields for errors 

       if (empty($_POST["txtName"])) { 
        $errors["txtName"] = "Please enter your name."; 
       } 

       if (empty($_POST["txtPhone"])) { 
        $errors["txtPhone"] = "Please enter your phone number."; 
       } 


       if (empty($_POST["txtEmail"])) { 
        $errors["txtEmail"] = "Please enter your email address."; 
       } else { 
        if (!eregi('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST["txtEmail"])))) { 
         $errors["txtEmail"] = "Please provide a valid email address."; 
        } 

       } 

       if (count($errors) < 1) { 

         $to = "[email protected]"; 
         $subject = 'Bave Designs Contact'; 
         $headers = "From:" . $_POST["txtEmail"] . "\r\n"; 
         $headers .= "MIME-Version: 1.0\r\n"; 
         $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; 
         $message = '<html><body style="font-family:Arial, Helvetica, sans-serif; font-size:12px;">'; 
         $message .= '<p><strong>Name:</strong> ' . $_POST["txtName"] . '<br /> 

            <strong>Phone:</strong> ' . $_POST["txtPhone"] . '<br /> 
            <strong>Email:</strong> ' . $_POST["txtEmail"] . '<br /> 

            <strong>Message:</strong><br />' . $_POST["txtComment"] . '</p> 
            </body> 
            </html>'; 
         if (!mail($to,$subject,$message,$headers)) { 

          $errors["send"] = "There was a problem sending your message. Please try again."; 
         } 

       } 
      } 
      <div id="contact-form"> 
        <?php 
       if (count($errors) > 0) { 
        echo '<ul style="color:red; padding:0 0 18px 22px;">'; 
        foreach ($errors as $error) { 
         echo "<li>" . $error . "</li>"; 
        } 
        echo "</ul>"; 
       } 
       ?> 
       <?php if ($_SERVER['REQUEST_METHOD'] == "POST" && count($errors) < 1) { ?> 
      <p class="success-message"><?php _e('Thank you! Your message has been sent.'); ?></p> 
      <?php } else { ?> 

      <form id="contact1" method="post" action="#message" class="contact-form"> 
       <p><label for="txtName">Name</label> 
       <input type="text" id="txtName" name="txtName" class="field" size="40" value="<?php echo $_POST['txtName'] ?>" /></p> 

       <p><label for="txtPhone">Phone</label> 
       <input type="text" id="txtPhone" name="txtPhone" class="field" size="40" value="<?php echo $_POST['txtPhone'] ?>" /></p> 

       <p><label for="txtEmail">Email</label> 
       <input type="text" id="txtEmail" name="txtEmail" class="field" size="40" value="<?php echo $_POST['txtEmail'] ?>" /></p> 

       <p><label for="txtComment">Message</label> 
       <textarea name="txtComment" id="txtComment" class="field" cols="40" rows="10"><?php echo $_POST['txtComment'] ?></textarea></p> 

       <p><input type="submit" id="btnSubmit" name="btnSubmit" class="button" value="Submit" /></p> 

      </form> 
      <?php } ?> 
     </div><!-- CONTACT FORM ENDS--> 

我切換wp_mail功能mail這是我所知道的是正確的。

任何幫助,將不勝感激。

在此先感謝。

+0

和文件有.php擴展名? – sinisake

+0

如果你得到的是PHP代碼,那麼你的服務器是miconfigurd,或者你說(使用.html文件擴展名),而不是.php。你也在使用古老的和高度廢棄的ereg函數,這是一個壞主意。 –

+1

你是在管理員'page'還是在'template'文件中寫上面的代碼? – Noor

回答

0

我的主要問題是,當我在瀏覽器中預覽我的網站時,它顯示了 表單上的PHP代碼。

那麼,如果我理解正確,您的PHP代碼將顯示在您的頁面中?

如果是這樣,我強烈建議您儘快與您的虛擬主機提供商聯繫,因爲您的Apache配置似乎存在一個大問題。

+0

我相信這只是愚蠢的文件擴展名,.php而不是.html,還有一個未封閉的.php標籤 – user2512446