2017-04-24 70 views
1

我想使用PHPMailer从我的contact.php页面发送表单数据。但它不能正常工作。它显示内部服务器错误。Contact.PHP表单内部服务器错误

这是我的contact.php表单代码。你能看到这段代码有什么问题吗?

<?PHP 

session_start(); 
$errors = isset($_SESSION['errors']) ? $_SESSION['errors'] : []; 
$fields = isset($_SESSION['fields']) ? $_SESSION['fields'] : []; 

require_once("/home/leasingexpertzz/public_html/helpers/security.php"); 
?> 


<!DOCTYPE html> 
<html lang="en-US"> 
    <head> 
     <title>Contact</title> 
    <?PHP include "header.php"; ?> 
    </head> 
    <body class="size-1140"> 

     <!-- TOP NAV WITH LOGO --> 
     <header> 
     <?PHP include "nav.php"; ?> 
     </header> 
     <section> 
     <div id="head"> 
      <div class="line"> 
       <h1>Leasing Expertz</h1> 
      </div> 
     </div> 
     <div id="content" class="left-align contact-page"> 
      <h1 class="sub-title">Reach us</h1> 
      <div class="line"> 
       <div class="margin"> 
        <div class="s-12 l-6"> 
        <h2>Leasing Expertz</h2> 
        <address> 
         <p><i class="icon-home icon"></i> Plot no. P-25 1st floor, Uppal South End, Near Eldico Mentions.</p> 
         <p><i class="icon-globe_black icon"></i> Sohna Road, Gurugram, Haryana, India</p> 
         <p><i class="icon-mail icon"></i> [email protected]</p> 
        </address> 
        <br /> 
        <h2>Social</h2> 
        <p class="fb"><a href="https://www.facebook.com/Leasing-Expertz-292379364250588/"><i class="icon-facebook icon"></i>Leasing Expertz</a></p> 
        <p class="linkedin"><a href="https://www.linkedin.com/"><i class="icon-linked_in icon"></i>Linked In</a></p> 
        <p class="twitter"><a href="https://twitter.com/"><i class="icon-twitter icon"></i>Tweeter</a></p> 
        </div> 
        <div class="s-12 l-6"> 
        <h2>Write to us</h2> 
        <form class="customform" method="post" action="email.php"> 
         <div class="s-12 l-7"><input name="senderEmail" placeholder="Your e-mail" title="Your e-mail" type="text" <?PHP echo isset($fields['email']) ? 'value="' . e($fields['email']) . '"' : '' ?> /> 
         <?PHP if(!empty($errors)) : ?> 
         <p> <?PHP echo implode('', $errors); ?></p> 
         <?PHP endif;?> 
         </div> 
         <div class="s-12 l-7"><input name="sender" placeholder="Your name" title="Your name" type="text" <?PHP echo isset($fields['name']) ? 'value="' . e($fields['name']) . '"' : '' ?>/> 
         <?PHP if(!empty($errors)) : ?> 
         <p> <?PHP echo implode('', $errors); ?></p> 
         <?PHP endif;?> 
         </div> 
         <div class="s-12 l-7"><input name="senderPhone" placeholder="Your phone number" title="Your Phone" type="text" <?PHP echo isset($fields['phone']) ? 'value="' . e($fields['phone']) . '"' : '' ?>/> 
         <?PHP if(!empty($errors)) : ?> 
         <p> <?PHP echo implode('', $errors); ?></p> 
         <?PHP endif;?> 
         </div> 
         <div class="s-12"><textarea placeholder="Your massage" name="message" rows="5" <?PHP echo isset($fields['message']) ? e($fields['message']) : '' ?>></textarea> 
         <?PHP if(!empty($errors)) : ?> 
         <p> <?PHP echo implode('', $errors); ?></p> 
         <?PHP endif;?> 
         </div> 
         <div class="s-12 m-6 l-4"><button type="submit">Submit Button</button></div> 
        </form> 
        </div> 
       </div> 
      </div> 
     </div> 
     <!-- MAP --> 
     <div id="map-block">  
       <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3508.9917339135745!2d77.03635061456353!3d28.419506282502333!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x390d229e71ef44dd%3A0x9931b80f30d32dd3!2sJMD+Megapolis!5e0!3m2!1sen!2sin!4v1492751226145" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen></iframe> 
     </div> 
     </section> 
     <!-- FOOTER --> 
     <footer> 
     <?PHP include "footer.php"; ?> 
     </footer> 
     <script type="text/javascript" src="owl-carousel/owl.carousel.js"></script> 
     <script type="text/javascript"> 
     jQuery(document).ready(function($) { 
      $("#owl-demo").owlCarousel({ 
      slideSpeed : 300, 
      autoPlay : true, 
      navigation : false, 
      pagination : false, 
      singleItem:true 
      }); 
      $("#owl-demo2").owlCarousel({ 
      slideSpeed : 300, 
      autoPlay : true, 
      navigation : false, 
      pagination : true, 
      singleItem:true 
      }); 
     }); 

     </script> 
    </body> 
</html> 

<?PHP 
unset($_SESSION['errors']); 
unset($_SESSION['fields']); 
?> 

以下是我的PHPMailer的email.php。

<?php 

session_start(); 
require_once("/home/leasingexpertzz/public_html/PHPMailer_5.2.0/PHPMailerAutoload.php"); 

$errors =[]; 
if(isset($_POST["senderEmail"], $_POST["sender"], $_POST["senderPhone"], $_POST["message"])){ 

    $fields = [ 
     'email'=> $_POST["senderEmail"], 
     'name' => $_POST["sender"], 
     'phone' => $_POST["senderPhone"], 
     'message' => $_POST["message"] 
    ]; 

    foreach ($fields as $field => $data) { 
     if(empty($data)){ 
      $errors[] = 'The' . $field . 'is required.'; 
     } 
    } 

    if(empty($errors)){ 
     $mail = new PHPMailer(); 

     $mail->IsSMTP();   // set mailer to use SMTP 
     $mail->Host = "localhost"; // specify main and backup server 
     $mail->Port = 25; 
     $mail->SMTPAuth = true;  // turn on SMTP authentication 
     $mail->Username = "[email protected]"; // SMTP username 
     $mail->Password = "xxxxxxxxxxx"; // SMTP password 

     $mail->From = "[email protected]"; 
     $mail->FromName = "Leasing Expert"; 

     $mail->AddAddress("[email protected]");     // name is optional 

     $mail->WordWrap = 50;         // set word wrap to 50 characters 

     $mail->IsHTML();         // set email format to HTML 

     $mail->Subject = "Here is the subject"; 
     $mail->Body = 'From: ' . $fields['name'] . '(' . $fields['email'] . ')' . $fields['phone'] . '<p>' . $fields['message'] .. '</p>'; 

     if($mail->Send()) 
     { 
      header("Location: http://leasingexpert.co.in/confirmation.php"); 
      die(); 
     } 
     else{ 
      $errors[] = 'Message could not be sent.'; 
     } 

     header("Location: http://leasingexpert.co.in/confirmation.php"); 

    } 

}else{ 
    $errors[] = 'Something went wrong.'; 
} 

$_SESSION['errors'] = $errors; 
$_SESSION['fields'] = $fields;  

?> 
+0

Wee需要知道你看到了什么错误。如果您在页面上看不到任何内容,他们在错误日志中说了什么?在开发时,您可能希望查看显示错误默认情况下http://stackoverflow.com/a/5438125/601299 – LeonardChallis

+0

致命错误:调用未定义的函数session_starts()在/ home/leasingexpertzz/public_html/email.php第3行 –

+0

没有错误消息了,空白页面正在提交。 –

回答

0

你应该尝试阅读日志,它可以在因您的操作系统和服务器上不同的地方,你正在使用(阿帕奇,Nginx的...)。

你也可以使用Xdebug的

0

内部服务器错误消息表明的东西,在一般情况下,是错误的编程。

在开发过程中,您必须启用错误日志登录PHP.ini文件。

然后你可以很容易地找出错误enter link description here

+0

我实际上是在虚拟主机上做的,我有error.log文件 –