php - Mails not working in Yii Using Xampp -


i'm building api , on aspect of sending mail. i'm getting mail not sent error. in api, front-end sends json request consisting of mail parameters.

{     "to":"gideonappoh@gmail.com",     "subject":"testing reviewer's page",     "body": "hello gideon",     "headers":"oksana.v@scopicsoftware.com" } 

i decode them , pass them through phpmail method in controller. not working, , can't find whats wrong. can me. these 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)) {             $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->host = 'stmp.emailsrvr.com';     $mail->smtpauth = true;     $mail->username = 'gideon.a@scopicsoftware.com';     $mail->password = 'n010grc7dsx';     $mail->mailer = 'stmp';     $mail->smtpdebug = 2;     $mail->port = 25;      //sending mail     $mail->setfrom($headers);     $mail->subject = $subject;     $mail->ishtml(true);     $mail->msghtml($body);     $mail->addaddress($to);      if(!$mail->send())         return $mail->errorinfo;      return true; } 

i have read many articles on configuring xampp , think should work still not working. getting response { "error":"mail not sent" }

thanks help.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -