-
Notifications
You must be signed in to change notification settings - Fork 1
/
Send.php
39 lines (29 loc) · 838 Bytes
/
Send.php
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
<?php
#Copyright (c) 2017 Rafal Marguzewicz pceuropa.net
namespace pceuropa\email;
use Yii;
use yii\validators\EmailValidator;
class Send extends \yii\base\Widget{
public $from = null;
public $to = null;
public $subject = null;
public $textBody = null;
public function init() {
parent::init();
if ($this->to === null) {
Yii::$app->session->setFlash('error', 'Please set recipient\'s email');
}
}
public function run() {
$validator = new \yii\validators\EmailValidator();
if ( $this->to && $validator->validate($this->to) ){
$message = Yii::$app->mailer->compose()
->setFrom($this->from)
->setTo($this->to)
->setSubject($this->subject)
->setTextBody($this->textBody);
$message->send();
}
}
}
?>