drze7794 2015-07-24 07:57
浏览 77
已采纳

phpmailer在slim中返回响应null

I am using slim framework to create api's for android app.In CreateUser api, i am sending mail to user using phpmailer.Phpmailer is sending the mails to user perfectly but my array response is returning null array response due to it.When i remove the code of phpmailer response is correct and when i add it ,it generates null reponse.

Here is my code in Dbhandler.php:

   $app->post('/requestPreview', function() use ($app) {
        verifyRequiredParams(array('fname', 'lname', 'email','event_code','app_version'));
        global $user_id;
        $response = array();

        $fname = urldecode($app->request->post('fname'));
        $lname = urldecode($app->request->post('lname'));
        $email =  urldecode($app->request->post('email'));
        $event_code =  urldecode($app->request->post('event_code'));
        $app_version =  urldecode($app->request->post('app_version'));
        $db = new DbHandler();
        //$db->sendmail($email);
        $res = $db->signup($fname, $lname, $email,$event_code,$app_version);

        if ($res['status']=="one") {
            //$password=$res['password'];
            $response["event_code"] = $event_code;
            $response["email"] = $email;
            $response["fname"] =$fname;
            $response["lname"] = $lname;
            $response["CreateUser"] = true;
                       $mail = new PHPMailer();  
                           $mail->IsSMTP();
                           $mail->SMTPDebug = 2;

                           $mail->Debugoutput = 'html';
                           $mail->Host = "smtp.gmail.com";
                           $mail->SMTPAuth = true;

                           $mail->Username = "abc.abc@gmail.com";
                           $mail->Password = "***********";
                           $mail->SMTPSecure = 'tls';
                           $mail->Port = 587;

                           $mail->From     = "abc.abc@gmail.com";
                           $mail->AddAddress($email);
                           $mail->isHTML(true); 
                           $mail->Subject  = "Welcome to www.abc.com .Your Account has been created and your password is:";
                           $mail->Body     = "Welcome to www.abc.com .Your Account has been created and your password is:";

                          $mail->send();    



        } else if ($res['status']=="two"){


            $response["error"] ="already_in_system";
            $response["fname"] = null;
            $response["lname"] = null;



        }
        echoRespnse(200, $response);
      });
  • 写回答

1条回答 默认 最新

  • dongzhaoshi8497 2015-07-24 10:13
    关注

    Update to latest PHPMailer and base your code on an up to date example, then read the troubleshooting docs. It's very likely you're running into Google auth issues.

    Your PHPMailer code never touches $response, suggesting it may be exiting prematurely due to an error, so trace what's happening in your function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题