Email.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace common\helpers;
  3. use Mailgun\Mailgun;
  4. use Yii;
  5. class Email
  6. {
  7. private static $mailKey = '4f64981556009f8e9fc2e112a65d3be3-67bd41c2-4e17cb05';
  8. /**
  9. * @param string $email
  10. * @param string $userName
  11. * @param string $password
  12. */
  13. public static function sendRegistrationEmail(string $email, string $userName, string $password)
  14. {
  15. $subject = \Yii::t('app', 'decRegistrationEmailSubject', []);
  16. $message = \Yii::t('app', 'decRegistrationEmailContent', ['userName' => $userName, 'passWord' => $password]);
  17. $mailer = Yii::$app->mailer;
  18. $mailer->useFileTransport = false;
  19. $response = $mailer->compose()
  20. ->setFrom(['no.reply.elken@gmail.com' => 'Elken'])
  21. ->setTo($email)
  22. ->setSubject($subject)
  23. ->setHtmlBody($message)
  24. ->send();
  25. LoggerTool::debug('sendRegistrationEmail' . sprintf('sendRegistrationEmail: %s', json_encode([$email, $userName, $password, $response])));
  26. }
  27. public static function sendEmail(string $email, string $userName, string $password)
  28. {
  29. $mg = Mailgun::create(self::$mailKey);
  30. $mg->messages()->send('ng-frontend-api.elken.com', [
  31. 'from' => 'Elken <no.reply.elken@gmail.com>',
  32. 'to' => $email,
  33. 'subject' => \Yii::t('app', 'decRegistrationEmailSubject', []),
  34. 'html' => \Yii::t('app', 'decRegistrationEmailContent', ['userName' => $userName, 'passWord' => $password]),
  35. ]);
  36. }
  37. }