<?php

namespace common\widgets;

use yii\base\Widget;

class Mailer extends Widget{
    public $message;
    public $email;
    public $text;
    public $subject;
    public $type;
    public $params;


    public function init(){

        parent::init();

    }

    public function run(){

        $mail = new \PHPMailer();
        
        /* */
        $mail->IsSMTP();
        $mail->SMTPDebug = 1;
        $mail->SMTPAuth = true;
        $mail->SMTPSecure = 'ssl';
        $mail->Host = 'smtp.gmail.com';
        $mail->Port = 465;
        $mail->CharSet = 'UTF-8';
        $mail->Username = "order.linija.svitla.ua@gmail.com";
        $mail->Password = "linija-svitla.ua339-92-33";
        $mail->SetFrom('order.linija.svitla.ua@gmail.com');
        $mail->Subject = $this->subject;
        $mail->MsgHTML($this->render($this->type, ['params' => $this->params]));
        $mail->AddAddress('bzika@ukr.net');
        $mail->AddAddress('dockdep@gmail.com');
        $mail->AddAddress($this->email);
        $mail->send();
        /* */
//        if(!$mail->send()) {
//            \Yii::$app->getSession()->setFlash('error', 'Mailer Error: ' . $mail->ErrorInfo);
//            return 'Mailer Error: ' . $mail->ErrorInfo;
//        } else {
//            return 'Message has been sent';
//        }
    }
}

