Email.php 1.5 KB

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