i using phpmailer send mails localhost in xampp. when test api in postman, takes long process request renders response status 200 no json response returned. below codes.
public function actionsendmail() { //getting request frontend $request = file_get_contents('php://input'); //decoding input array $input = json_decode($request, true); //validating request if (is_null($input)) { $response = json_encode(['error' => 'bad input']); die($response); } else { //mail parameters $to = $input['to']; $subject = $input['subject']; $body = $input['body']; $headers = $input['headers']; //sending mail if($result = $this->sendmail($to, $subject, $body, $headers) === true) { $response = json_encode(['success' => true]); echo $response; } else { $response = json_encode(['error' => 'mail not sent']); die($response); } } } private function sendmail ($to, $subject, $body, $headers) { //configurating php mailer $mail = new phpmailer(); $mail->issmtp(); $mail->host = 'secure.emailsrvr.com'; $mail->port = 995; $mail->smtpauth = true; $mail->username = 'example@example.com'; $mail->password = '****'; $mail->smtpsecure = 'ssl'; $mail->wordwrap = 50; $mail->ishtml(true); $mail->setfrom('redacted@example.com'); $mail->addreplyto($headers); $mail->subject = $subject; $mail->msghtml($body); $mail->addaddress($to, ""); if(!$mail->send()) return $mail->errorinfo; return true; } thanks time.
you need test mail sending code in isolation - errors being hidden behind other code. long delay means you're having network timeout, either due bad connectivity or dns timeout. try setting $mail->smtpdebug = 3; can see connection errors. check phpmailer troubleshooting guide.
Comments
Post a Comment