Created
November 28, 2018 21:15
-
-
Save gpedro/3ed6561535c2251c834aa7c63e64ca51 to your computer and use it in GitHub Desktop.
FallbackMailChannel para Laravel Notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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