Conditions | 7 |
Paths | 16 |
Total Lines | 30 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 9.5839 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
34 | 7 | public function sendMessage(string $to, string $subject, string $view, array $params = [], array $attach = []): bool |
|
35 | { |
||
36 | 7 | $message = \Yii::$app->getMailer()->compose($view, $params); |
|
37 | |||
38 | 7 | if (count($attach)) { |
|
39 | foreach ($attach as $file) { |
||
40 | $message->attach($file); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | 7 | if (strlen($this->params->emailMain) && strlen($this->params->emailName)) { |
|
45 | 1 | $message->setFrom([$this->params->emailMain => $this->params->emailName]); |
|
46 | } |
||
47 | |||
48 | 7 | $to = explode(',', $to); |
|
49 | 7 | $message->setTo($to); |
|
50 | |||
51 | 7 | if (strlen($this->params->emailPrefix)) { |
|
52 | $message->setSubject($this->params->emailPrefix . ': ' . $subject); |
||
53 | } else { |
||
54 | 7 | $message->setSubject($subject); |
|
55 | } |
||
56 | |||
57 | try { |
||
58 | 7 | return $message->send(); |
|
59 | } catch (\Exception $e) { |
||
60 | Yii::error($e); |
||
61 | return false; |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 |