Blame view

common/widgets/Mailer.php 1.21 KB
4253cbec   root   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
  <?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();
8ec69373   Yarik   Orders.
25
26
          
          /* */
4253cbec   root   first commit
27
          $mail->IsSMTP();
8ec69373   Yarik   Orders.
28
29
30
31
32
          $mail->SMTPDebug = 1;
          $mail->SMTPAuth = true;
          $mail->SMTPSecure = 'ssl';
          $mail->Host = 'smtp.gmail.com';
          $mail->Port = 465;
4253cbec   root   first commit
33
          $mail->CharSet = 'UTF-8';
8ec69373   Yarik   Orders.
34
35
36
          $mail->Username = "proekant.net@gmail.com";
          $mail->Password = "proektant112233";
          $mail->SetFrom('proekant.net@gmail.com');
4253cbec   root   first commit
37
38
          $mail->Subject = $this->subject;
          $mail->MsgHTML($this->render($this->type, ['params' => $this->params]));
8ec69373   Yarik   Orders.
39
          $address = "slava.up@gmail.com";
4253cbec   root   first commit
40
41
          $mail->AddAddress($address);
          $mail->AddAddress($this->email);
8ec69373   Yarik   Orders.
42
          /* */
4253cbec   root   first commit
43
          if(!$mail->send()) {
4253cbec   root   first commit
44
              \Yii::$app->getSession()->setFlash('error', 'Mailer Error: ' . $mail->ErrorInfo);
4253cbec   root   first commit
45
46
              return 'Mailer Error: ' . $mail->ErrorInfo;
          } else {
4253cbec   root   first commit
47
48
49
              return 'Message has been sent';
          }
      }
4253cbec   root   first commit
50
  }