Skip to content

Send mails in laravel with custom config you can set on the fly

License

Notifications You must be signed in to change notification settings

emchooo/laravel-flymail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Flymail

About

Laravel Flymail adds Mail::config() method to Laravel\Mail. Config method will setup mail config data on the fly. Use Flymail if you need to send Mails with dynamic credentials you store in DB or other configs. Since it just extends Laravel's Mail and adds config method, everything else remains same.

Installation

composer require emchooo/laravel-flymail

Usage

use Illuminate\Support\Facades\Mail;

// get config file from DB or other source

// SES config
$config = [ 
	'driver' => 'ses', 
	'key' => 'xxx', 
	'secret' => 'xxx', 
	'from' => [ 
		'address' => 'address@mail.com', 
		'name' => 'Name' 
		] 
	];
// SMTP config
$config = [
	'driver' => 'smtp',
	'host' => 'smtp.xxx.io', 
	'port' => 2525,
	'username' => 'xxx',
	'password' => 'xxx',
	'encription' => 'null'
	'from' => [ 
		'address' => 'address@mail.com', 
		'name' => 'Name' 
		]
	];

Mail::config($config)->to($request->user())->send(new OrderShipped($order));

NOTE ON QUEUES

If you use Mail::config than don't use ->queue(); , use ->send(); . If you use queue on Mail then it will use config from /config/mail.php while sending. Might try to fix that one day.

If you need to queue Mail with custom config then use Jobs.

	SendEmail::dispatch($config, $order);

	/**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($config, $order)
    {
        $this->config = $config;
        $this->order = $order;
    }
    
	 /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Mail::config($this->config)
        ->to($this->order->email)
        ->send(new OrderShipped($this->order));
    }

License

The MIT License (MIT). Please see License File for more information.

About

Send mails in laravel with custom config you can set on the fly

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages