Mailer.php 1.21 KB
<?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->CharSet = 'UTF-8';
//        $mail->SMTPDebug = 1;
        $mail->SMTPAuth = true;
        $mail->SMTPSecure = 'ssl';
        $mail->Host = "smtp.gmail.com";
        $mail->Port = 465; // or 587
        $mail->IsHTML(true);
        $mail->Username = "login@gmail.com";  // Google email account
        $mail->Password = "password";  // Password to this account
        $mail->SetFrom("leaf@electrocars.ua");
        $mail->isHTML(true);
        $mail->Subject = $this->subject;
        $mail->Body = $this->render($this->type, ['params' => $this->params]);
        $mail->AddAddress('zhegal@gmail.com');
        $mail->AddAddress('pmartweb1@gmail.com');
        if(!$mail->Send()) {
            echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
            echo "Message has been sent";
        }
    }

}