Blame view

app/models/Call.php 1.4 KB
bf807468   Alex Savenko   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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  <?php

  namespace app\models;

  

  use Yii;

  use yii\base\Model;

  

  

  class Call extends Model

  {

      public $name;

      public $phone;

      public $body;

      

      public function rules()

      {

          return [

              [['name', 'phone'], 'required','whenClient' => true],

              //['email', 'email'],

              [['body'], 'safe'],

          ];

      }

      

      public function attributeLabels()

      {

          return [

              'name' => 'Имя',

              'phone'=>'Телефон',

              'body'=>'Сообщение',

          ];

      }

      

      public function contact($email)

      {

          if ($this->validate()) {

                          $body = '';

                          $body .= 'Имя: '.$this->name;

                          $body .= "\n\r";

                          $body .= 'Телефон: '.$this->phone;

                          $body .= "\n\r";

                          $body .= 'Сообщение: '.$this->body;

                          $body .= "\n\r"; 

                          

              Yii::$app->mailer->compose()

                  ->setTo($email)

                  ->setFrom(['send@artweb.ua' => 'send'])

                  ->setSubject('ОБРАТНЫЙ ЗВОНОК на сайте Бубочка')

                  ->setTextBody($body)

                  ->send();

              return true;

          } else {

              return false;

          }

      }    

      

  }