我正在使用slim框架为Android app创建api。在CreateUser api中,我使用phpmailer发送邮件给用户.Phpmailer将邮件发送给用户完美但我的数组响应返回null数组响应到期当我删除phpmailer的代码响应是正确的,当我添加它时,它会生成null响应。
这是我在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);
});
答案 0 :(得分:0)
更新至latest PHPMailer并将您的代码基于an up to date example,然后阅读the troubleshooting docs。您很可能会遇到Google身份验证问题。
您的PHPMailer代码永远不会触及$response
,表明它可能因错误而过早退出,因此请跟踪您的函数中发生的事情。