MailerServiceProvider.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. // Copyright 2019 Hackware SpA <human@hackware.cl>
  3. // Part of "Hackware Web Services Core", released under the MIT License terms.
  4. namespace Hawese\Core\Providers;
  5. use Hawese\Core\Mailer;
  6. use Illuminate\Support\ServiceProvider;
  7. class MailerServiceProvider extends ServiceProvider
  8. {
  9. public function register()
  10. {
  11. $this->mergeConfigFrom(__DIR__ . '/../../config/mail.php', 'mail');
  12. $this->app->bind(Mailer::class, function ($app) {
  13. $config = $app['config']['mail'];
  14. $mailer = new Mailer(true); // True enables exceptions
  15. $mailer->CharSet = Mailer::CHARSET_UTF8;
  16. $mailer->setFrom($config['from_address'], $config['from_name']);
  17. $mailer->addReplyTo(
  18. $config['reply_to_address'],
  19. $config['reply_to_name']
  20. );
  21. switch ($config['driver']) {
  22. case 'smtp':
  23. $mailer->isSMTP();
  24. $mailer->Host = $config['host'];
  25. $mailer->Port = $config['port'];
  26. if ($config['username']) {
  27. $mailer->SMTPAuth = true;
  28. $mailer->Username = $config['username'];
  29. $mailer->Password = $config['password'];
  30. }
  31. if ($config['encryption']) {
  32. $mailer->SMTPSecure = $config['encryption'];
  33. }
  34. break;
  35. case 'sendmail':
  36. $mailer->isSendmail();
  37. break;
  38. default:
  39. $mailer->isMail();
  40. }
  41. return $mailer;
  42. });
  43. }
  44. }