Skip to content

Instantly share code, notes, and snippets.

@gpedro
Created November 28, 2018 21:15
Show Gist options
  • Save gpedro/3ed6561535c2251c834aa7c63e64ca51 to your computer and use it in GitHub Desktop.
Save gpedro/3ed6561535c2251c834aa7c63e64ca51 to your computer and use it in GitHub Desktop.
FallbackMailChannel para Laravel Notifications
<?php
namespace App\Channels;
use Illuminate\Mail\Mailer;
use Illuminate\Mail\Markdown;
use Illuminate\Mail\TransportManager;
use Illuminate\Notifications\Channels\MailChannel;
class FallbackMailChannel extends MailChannel
{
public function __construct(Mailer $mailer, Markdown $markdown)
{
foreach (['HOST', 'PORT', 'USERNAME', 'PASSWORD', 'ENCRYPTION', 'FROM_ADDRESS'] as $param) {
$suffix = strtolower($param);
if ($param === 'FROM_ADDRESS') {
$suffix = 'from.address';
}
config()->set("mail.{$suffix}", env("MAIL_{$param}_ALT"));
}
app()->singleton('swift.transport', function ($app) {
return new TransportManager($app);
});
$swift = new \Swift_Mailer(app('swift.transport')->driver());
$mailer->setSwiftMailer($swift);
$mailer->alwaysFrom(config('mail.from.address'), config('mail.from.name'));
parent::__construct($mailer, $markdown);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment