Conditions | 4 |
Paths | 6 |
Total Lines | 28 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
40 | public function sendEmail($viewFile, $subject, $email, array $params = []) |
||
41 | { |
||
42 | // Default to this view file |
||
43 | $viewFilePath = '@app/views/mail/en-US/' . $viewFile . '.twig'; |
||
44 | |||
45 | // Scan the "Accept-Language" header to see if we have a better viewfile |
||
46 | $languages = Yii::$app->request->getAcceptableLanguages(); |
||
47 | foreach ($languages as $language) { |
||
48 | $vfp = '@app/views/mail/' . $language . '/' . $viewFile . '.twig'; |
||
49 | if (\file_exists(Yii::getAlias($vfp))) { |
||
50 | $viewFilePath = $vfp; |
||
51 | break; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | $view = Yii::$app->view->renderFile($viewFilePath, $params); |
||
56 | |||
57 | if ($this->realSend === true) { |
||
58 | return Yii::$app->mailer->compose() |
||
59 | ->setFrom($this->fromEmail) |
||
60 | ->setTo($email) |
||
61 | ->setSubject($subject) |
||
62 | ->setHtmlBody($view) |
||
63 | ->send(); |
||
64 | } |
||
65 | |||
66 | return true; |
||
67 | } |
||
68 | } |