<?php

namespace common\components;
use PHPMailer\PHPMailer\PHPMailer;
use yii\base\Widget;

class Mailer extends Widget{
    public $message;
    public $email = 'dockdep@gmail.com';
    public $text;
    public $subject;

    public function init(){

        parent::init();

    }

    public function run(){

        $mail = new PHPMailer();

        $mail->IsSMTP();

        $mail->CharSet = 'UTF-8';
        $mail->Username = "adwords@artweb.ua";
        $mail->Password = "eks,ybcm5hfp";
        $mail->SetFrom('dockdep@gmail.com');
        $mail->Subject = $this->subject;
        $mail->MsgHTML($this->text);
        $address = "dockdep@gmail.com";
        $mail->AddAddress($address);
        if(!$mail->send()) {
            \Yii::$app->getSession()->setFlash('error', 'Mailer Error: ' . $mail->ErrorInfo);
            return 'Mailer Error: ' . $mail->ErrorInfo;
        } else {
            \Yii::$app->getSession()->setFlash('success', 'Мастер-приемщик свяжется с вами в ближайшее время');
            return 'Message has been sent';
        }
    }

}

