Blame view

common/components/Mailer.php 1.08 KB
7b08eb78   Administrator   15.04.16 seo widget
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  <?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 = "dockdep@gmail.com";
          $mail->Password = "k0l0b04eg";
          $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';
          }
      }
  
  }