Phpmailer用ajax导致内部错误500

时间:2016-11-11 13:00:39

标签: php jquery ajax phpmailer

我在我的注册页面中包含我的phpmailer并使用简单的ajax来推送数据与db交互...一切正常我的localhost但是当我上传到服务器时,我得到这个内部错误500 HTML

<script>
$(document).ready(function(){
    $("#register-btn").click(function(){

        var name=$("#hostel-name").val();
        var email=$("#email").val();
        var conf_email=$("#conf-email").val();
        var password=$("#password").val();


        $.ajax({
            url:"functions/register.php",
            data:{
                name:name,
                email:email,
                conf_email:conf_email,
                password:password
                },
            type:"POST",
            success:function(data){
                $("#result").html(data);
            }
        });
    });
   });

</script>
<section id="result">

</section>

<section class="row">
    <section class="container">
        <section class="col-md-offset-4 col-md-4" id="register">
        <h1 class="title text-center" style="border-left:0;margin-top: -10px;"><a href="index">Accomonde</a></h1>
           <h3 class="title">Sign Up</h3>
           <br>

                <section class="form-group col-md-12">
                <label> Name</label>
                <input type="text" class="form-control" name="hostel-name" id="hostel-name" autocomplete="off" placeholder="Hostel Name" required>
                </section>

                <section class="form-group col-md-12">
                <label>Email</label>
                <input type="email" class="form-control" name="email" id="email" autocomplete="off" placeholder="Your Email" required>
                </section>

                <section class="form-group col-md-12">
                <label>Confirm Email</label>
                <input type="email" class="form-control" name="conf-email" id="conf-email" autocomplete="off" placeholder="Confirm Your Email" required>
                </section>

                <section class="form-group col-md-12">
                <label>Password</label>
                <input type="password" class="form-control" name="password" id="password" autocomplete="off" placeholder="Your Password" required>
                <br>
                <section class="form-group">
                    <button class="form-control btn-primary" name="register" id="register-btn" ><span class="fa fa-paper-plane"> Sign Up</span></button>
                </section>
                <section class="form-group">
                    <ul class="list-inline">
                        <li class="pull-left">Already Have an Account?</li>
                        <li class="pull-right"><a href="login">Log in!</a>   </li>
                    </ul>
                </section>

        </section>
    </section>
 </section>

```

这是我的php脚本

<?php
    require_once '../libs/phpmailer/PHPMailerAUtoload.php';
    try{
        include '../database/connection.php';
        $hostel_name=$_POST['name'];
        $email=filter_var($_POST['email'],FILTER_VALIDATE_EMAIL);
        $password=hash('sha256',$_POST["password"]);
        $confemail=filter_var($_POST['conf_email'],FILTER_VALIDATE_EMAIL);
        $confirm_code=md5(uniqid(rand()));
        $user_id=md5(rand(0,10000));
         //new block added
            if($name="" or $email=="" || $password=="" || $confemail==""  ){echo '<p  class="alert alert-danger text-center">Please Make Sure All Fields Are Filled <span class="close pull-right"><span class="close pull-right"> <a href="#" >&times;</a></span></p>';}

          elseif($email==$confemail){
       $query=$dbc->query("select * from users where email='$email'");


     if($result=$query->fetch(PDO::FETCH_NUM)==1){ echo '
    <p class="alert alert-danger text-center">We already have someone with that email <span class="close pull-right"><span class="close pull-right"> <a href="#" >&times;</a></span></p>'; }elseif($result=$query->fetch(PDO::FETCH_NUM)==0){ 
      $data_result=$dbc->query("insert into users(hostel_name,email,password,confirm_code,user_id) values('$hostel_name','$email','$password','$confirm_code','$user_id')");
     if($data_result){
          $m = new PHPMailer;
        $m ->isSMTP();
        $m->SMTPAuth=true;

        // debugging
        // $m->SMTODebug=1
        // endof debug
        $m->Host="smtp.gmail.com";
        $m->Username="karsoft92@gmail.com";
        $m->Password="lollypop28:)";
        $m->SMTPSecure='ssl';
        $m->Port=465;
        $m->isHtml(true);

        $m->Subject = 'Welcome to Efie';
        ob_start();
include '../views/email/register-email.php';
$body = ob_get_contents();

   $m->msgHTML($body, dirname(__FILE__));
        $m->FromName="Efie Ghana";
        $m->AddAddress($email,$hostel_name);
        ob_end_clean();
        $m->send();

       echo '<p class="alert alert-success text-center error-message"> You\'re almost there!  Check your inbox to activate your account.</p>';

        }

   }
 }
}catch(Exception $e){echo '<p class="alert alert-danger text-center error-message">Something is not right <span class="pull-right close"> <a href="#" >&times;</a></span></p>';}

$dbc=null;





 ?>

```

1 个答案:

答案 0 :(得分:1)

Linux文件系统通常区分大小写,因此不起作用:

require_once '../libs/phpmailer/PHPMailerAUtoload.php';

应该是:

require_once '../libs/phpmailer/PHPMailerAutoload.php';

通常,每当出现错误500时,您都可以在Web服务器的日志文件中找到有关错误的更多详细信息。

此外,您的脚本容易受到SQL注入攻击 - 当您检查电子邮件地址是否有效时,可能会有一个字符串,该字符串是有效的电子邮件地址,也是有效的SQL注入攻击。总是逃避你在SQL中的内容。