1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace terabytesoft\mailer\user; |
4
|
|
|
|
5
|
|
|
use yii\base\Component; |
6
|
|
|
use yii\db\ActiveRecord; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class Mailer |
10
|
|
|
* |
11
|
|
|
**/ |
12
|
|
|
class Mailer extends Component |
13
|
|
|
{ |
14
|
|
|
public $mailerComponent; |
15
|
|
|
public $sender; |
16
|
|
|
public $viewPath = '@terabytesoft/mailer/user/views'; |
17
|
|
|
|
18
|
|
|
protected $confirmationSubject; |
19
|
|
|
protected $newPasswordSubject; |
20
|
|
|
protected $reconfirmationSubject; |
21
|
|
|
protected $recoverySubject; |
22
|
|
|
protected $welcomeSubject; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* sendConfirmationMessage |
26
|
|
|
* |
27
|
|
|
* sends an email to a user with confirmation link |
28
|
|
|
**/ |
29
|
1 |
|
public function sendConfirmationMessage(string $email, array $params): bool |
30
|
|
|
{ |
31
|
1 |
|
return $this->sendMessage( |
32
|
1 |
|
$email, |
33
|
1 |
|
\Yii::$app->params['mailer.user.subject.reconfirmation'], |
34
|
1 |
|
'confirmation', |
35
|
|
|
[ |
36
|
1 |
|
'tokenUrl' => $params['tokenUrl'] |
37
|
|
|
] |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* sendGeneratedPassword |
43
|
|
|
* |
44
|
|
|
* sends a new generated password to a user |
45
|
|
|
**/ |
46
|
1 |
|
public function sendGeneratedPassword(string $email, array $params): bool |
47
|
|
|
{ |
48
|
1 |
|
return $this->sendMessage( |
49
|
1 |
|
$email, |
50
|
1 |
|
\Yii::$app->params['mailer.user.subject.password'], |
51
|
1 |
|
'new_password', |
52
|
|
|
[ |
53
|
1 |
|
'password' => $params['password'] |
54
|
|
|
] |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* sendReconfirmationMessage. |
60
|
|
|
* |
61
|
|
|
* sends an email to a user with reconfirmation link |
62
|
|
|
**/ |
63
|
2 |
|
public function sendReconfirmationMessage(string $email, array $params): bool |
64
|
|
|
{ |
65
|
2 |
|
return $this->sendMessage( |
66
|
2 |
|
$email, |
67
|
2 |
|
\Yii::$app->params['mailer.user.subject.reconfirmation'], |
68
|
2 |
|
'reconfirmation', |
69
|
|
|
[ |
70
|
2 |
|
'tokenUrl' => $params['tokenUrl'] |
71
|
|
|
] |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* sendRecoveryMessage |
77
|
|
|
* |
78
|
|
|
* sends an email to a user with recovery link |
79
|
|
|
**/ |
80
|
1 |
|
public function sendRecoveryMessage(string $email, array $params): bool |
81
|
|
|
{ |
82
|
1 |
|
\Yii::$app->session->set('sendRecoveryMessage', true); |
|
|
|
|
83
|
1 |
|
return $this->sendMessage( |
84
|
1 |
|
$email, |
85
|
1 |
|
\Yii::$app->params['mailer.user.subject.recovery'], |
86
|
1 |
|
'recovery', |
87
|
|
|
[ |
88
|
1 |
|
'tokenUrl' => $params['tokenUrl'] |
89
|
|
|
] |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* sendWelcomeMessage |
95
|
|
|
* |
96
|
|
|
* sends an email to a user after registration |
97
|
|
|
**/ |
98
|
1 |
|
public function sendWelcomeMessage(string $email, array $params): bool |
99
|
|
|
{ |
100
|
1 |
|
return $this->sendMessage( |
101
|
1 |
|
$email, |
102
|
1 |
|
\Yii::$app->params['mailer.user.subject.welcome'], |
103
|
1 |
|
'welcome', |
104
|
|
|
[ |
105
|
1 |
|
'accountGeneratingPassword' => $params['accountGeneratingPassword'], |
106
|
1 |
|
'password' => $params['password'], |
107
|
1 |
|
'showPassword' => $params['showPassword'], |
108
|
1 |
|
'tokenUrl' => $params['tokenUrl'] |
109
|
|
|
] |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* sendMessage |
115
|
|
|
**/ |
116
|
6 |
|
protected function sendMessage(string $to, string $subject, string $view, array $params = []): bool |
117
|
|
|
{ |
118
|
6 |
|
$mailer = $this->mailerComponent === null ? \Yii::$app->mailer : \Yii::$app->get($this->mailerComponent); |
119
|
|
|
|
120
|
6 |
|
$mailer->viewPath = $this->viewPath; |
121
|
|
|
|
122
|
6 |
|
return $mailer->compose(['html' => $view, 'text' => 'text/' . $view], $params) |
|
|
|
|
123
|
6 |
|
->setTo($to) |
124
|
6 |
|
->setFrom( |
125
|
6 |
|
[\Yii::$app->params['mailer.user.email.sender'] => \Yii::$app->params['mailer.user.email.sender.name']] |
126
|
|
|
) |
127
|
6 |
|
->setSubject($subject) |
128
|
6 |
|
->send(); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.