Blame view

common/widgets/Mailer.php 1.19 KB
eb56e5f2   Administrator   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  <?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';

5cbf6e57   Alexey Boroda   -Mail dances
28
          $mail->SMTPDebug = 2;

eb56e5f2   Administrator   first commit
29
          $mail->SMTPAuth = true;

5cbf6e57   Alexey Boroda   -Mail dances
30
          $mail->SMTPSecure = 'tls';

eb56e5f2   Administrator   first commit
31
          $mail->Host = "smtp.gmail.com";

5cbf6e57   Alexey Boroda   -Mail dances
32
          $mail->Port = 587; // 465 or 587

4bf42036   Alexey Boroda   -Modals ready
33
34
          $mail->Username = "nissanleaf17@gmail.com";  // Google email account

          $mail->Password = "parol123";  // Password to this account

eb56e5f2   Administrator   first commit
35
36
37
38
          $mail->SetFrom("leaf@electrocars.ua");

          $mail->isHTML(true);

          $mail->Subject = $this->subject;

          $mail->Body = $this->render($this->type, ['params' => $this->params]);

4bf42036   Alexey Boroda   -Modals ready
39
          $mail->AddAddress('kennen.md@gmail.com');

5cbf6e57   Alexey Boroda   -Mail dances
40
          $mail->AddAddress('pmartweb1@gmail.com');

eb56e5f2   Administrator   first commit
41
42
43
44
45
46
47
48
49
          if(!$mail->Send()) {

              echo "Mailer Error: " . $mail->ErrorInfo;

          } else {

              echo "Message has been sent";

          }

      }

  

  }