I am using Slim framework for creating my api. I am sending email using phpmailer. The mail is sending correctly. But my problem is that $mail->send()
is firing my api twice due to which my response is wrong. Please tell me why $mail->send()
is calling my api again in slim and how can I resolve it. Here is my code
$app->post('/requestPreview', function () use ($app) {
// $file = fopen('testphpmailer.txt',"w");
verifyRequiredParams(array('fname', 'lname', 'email', 'event_code', 'app_version'));
global $user_id, $condition;
$response = array();
$fname = $app->request->post('fname');
$lname = $app->request->post('lname');
$email = $app->request->post('email');
$event_code = $app->request->post('event_code');
$app_version = $app->request->post('app_version');
//echo fwrite($file,"incoming vaiables: Firstname=".$fname);
//echo fwrite($file,"incoming vaiables: Lastname=".$lname);
//echo fwrite($file,"incoming vaiables: Email=".$email);
//echo fwrite($file,"incoming vaiables: event_code=".$event_code);
//echo fwrite($file,"incoming vaiables: app_version=".$app_version);
$db = new DbHandler();
//$db->sendmail($email);
$res = $db->signup($fname, $lname, $email, $event_code, $app_version);
//echo fwrite($file,"Result".$res['status']);
if ($res['status'] == "one") {
//echo fwrite($file,"Inside If".$res['status']);
$password = $res['password'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->IsHTML(true);
$mail->Username = "abc@gmail.com";
$mail->Password = "*******";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->From = "abc@gmail.com";
$mail->AddAddress("abc@gmail.com");
$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(); /*When this line runs then it it send the gmail and my api is called and below mentioned response is never executed*/
$response["event_code"] = $event_code;
$response["email"] = $email;
$response["fname"] = $fname;
$response["lname"] = $lname;
$response["CreateUser"] = false;
echoRespnse(200, $response);
} else {
// echo fwrite($file,"Inside else = ".$res['status']);
$response["error"] = "already in system";
$response["fname"] = "null";
$response["lname"] = "null";
echoRespnse(200, $response);
}
//echo fwrite($file,"Hello World. Testing!");
//fclose($file);
});