Email.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace common\helpers;
  3. use Yii;
  4. class Email
  5. {
  6. /**
  7. * @param string $email
  8. * @param string $userName
  9. * @param string $password
  10. * @return false|void
  11. */
  12. public static function sendRegistrationEmail(string $email, string $userName, string $password)
  13. {
  14. if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
  15. return false;
  16. }
  17. $subject = \Yii::t('app', 'decRegistrationEmailSubject', []);
  18. $message = \Yii::t('app', 'decRegistrationEmailContent', ['userName' => $userName, 'passWord' => $password]);
  19. $mailer = Yii::$app->mailer;
  20. $mailer->useFileTransport = false;
  21. $response = $mailer->compose()
  22. ->setFrom('eshop-noreply@elken.com')
  23. ->setTo($email)
  24. ->setSubject($subject)
  25. ->setHtmlBody($message)
  26. ->send();
  27. LoggerTool::debug('sendRegistrationEmail' . sprintf('sendRegistrationEmail: %s', json_encode([$email, $userName, $password, $response])));
  28. }
  29. }