phpmailer在苗条中返回响应null [英] phpmailer returning response null in slim

查看:144
本文介绍了phpmailer在苗条中返回响应null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用苗条的框架来为Android应用程序创建api.在CreateUser api中,我正在使用phpmailer向用户发送邮件.Phpmailer正在向用户发送邮件,但是我的数组响应因此返回了空数组响应.我删除了phpmailer响应的代码是正确的,当我添加它时,它会生成空响应.

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.

这是我在Dbhandler.php中的代码:

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);
      });

推荐答案

更新为最新的PHPMailer 和基础您的代码在最新示例上,然后阅读疑难解答文档.您很有可能遇到了Google身份验证问题.

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.

您的PHPMailer代码从未碰过$response,这表明它可能由于错误而过早退出,因此请跟踪函数中发生的事情.

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

这篇关于phpmailer在苗条中返回响应null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆