简体   繁体   English

Contact.PHP表单内部服务器错误

[英]Contact.PHP Form Internal Server error

I am trying to send form data from my contact.php page using PHPMailer. 我正在尝试使用PHPMailer从我的contact.php页面发送表单数据。 But it is not working properly. 但它不能正常工作。 It is showing internal server error. 它显示内部服务器错误。

This is my contact.php form code. 这是我的contact.php表单代码。 Can you see what is wrong with this code. 你能看出这段代码有什么问题吗?

<?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> leasingexpertzz@gmail.com</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']);
?>

Below is my email.php for PHPMailer. 下面是我为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 = "admin@leasingexpert.co.in";  // SMTP username
        $mail->Password = "xxxxxxxxxxx"; // SMTP password

        $mail->From = "admin@leasingexpert.co.in";
        $mail->FromName = "Leasing Expert";

        $mail->AddAddress("admin@leasingexpert.co.in");                  // 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;    

?>

You should try reading the logs, which can be in different places depending on your OS and the server you're using (apache, nginx...). 您应该尝试阅读日志,这些日志可能位于不同的位置,具体取决于您的操作系统和您正在使用的服务器(apache,nginx ...)。

You could also use xdebug 你也可以使用xdebug

Internal Server Error messages indicate that something, in general, is wrong in programming. 内部服务器错误消息表明编程中通常存在错误。

While developing you have to enable to error log in PHP.ini file. 在开发时,您必须启用错误登录PHP.ini文件。

Then you can easily find out the error enter link description here 然后你可以在这里轻松找出错误输入链接描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM