Laravel 5
PHP 7.1+
No commit activity in last 2 years
No release in over 2 years
Override helper Mailer from laravel to hook the sender
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

mockery/mockery
^1.0
phpunit/phpunit
^7.0

Runtime

dev-laravel-5.7#d9cc177760727fa7ac4df0a322cc3e28c0c074c7
 Project Readme

Scrutinizer Code Quality Code Coverage Build Status Total Downloads Latest Stable Version License

Laravel 5 MailerSaver

Mailer saver extend the laravel 5 mailer.

  • Add the possibility to override the to,cc,bcc of your mail without modify your implementation.
  • Add the possibility to get your template mail, subject, cc, bcc and type from a model.

Table of contents

  1. Installation
  2. Config file
  3. View
  4. Send an email

Installation

Add on your composer.json

    "require": {
        "distilleries/mailersaver": "2.*",
    }

run composer update.

Add Service provider to config/app.php:

    'providers' => [
        // ...
       Distilleries\MailerSaver\MailerSaverServiceProvider::class,
       Wpb\String_Blade_Compiler\ViewServiceProvider::class,
    ],

And Facade (also in config/app.php) replace the laravel facade Mail

    'aliases' => [
        // ...
       'Mail' => 'Distilleries\MailerSaver\Facades\Mail',
    ]

You need to provide a model of data, simply add on your register method a new instance of your model in your app/Providers/AppServiceProvider.php:

    public function register()
	{
		$this->app->singleton('Distilleries\MailerSaver\Contracts\MailModelContract', function ($app) {
            return new App\Email;
        });

	}

In this case I return a Email model instance. This model just implement the contract Distilleries\MailerSaver\Contracts\MailModelContract.

To Publish the model:

php artisan vendor:publish --provider="Distilleries\MailerSaver\MailerSaverServiceProvider" --tag="models"

To Publish the migration:

php artisan vendor:publish --provider="Distilleries\MailerSaver\MailerSaverServiceProvider" --tag="migrations"

Config file

You can publish the config file with the command line:

php artisan vendor:publish --provider="Distilleries\MailerSaver\MailerSaverServiceProvider"
    return [
        'template' => 'mailersaver::default',
        'override' => [
            'enabled' => env('MAILERSAVER_ENABLED', false),
            'to' => env('MAILERSAVER_TO', 'default1@mailto.com,default2@mailto.com'),
            'cc' => env('MAILERSAVER_CC', ''),
            'bcc' => env('MAILERSAVER_BCC', ''),
        ],
    ];
Field Description
template Global template when you put the content of your mail.
override An array with all the config to hoock the mail send.
enabled Enable the override of the mail. If in true that send the email with the to, cc, bcc
to Use to send an email when the override parameter is set to true
cc Use to send an email when the override parameter is set to true
bcc Use to send an email when the override parameter is set to true

View

To override the view you can give a new template on the configuration or modify the current one. Before modify it you have to publish it:

php artisan vendor:publish --provider="Distilleries\MailerSaver\MailerSaverServiceProvider" --tag="views"

Send an email

It's exactly the same than the laravel mailer.

Example:

Mail::send('emails.welcome', ['key' => 'value'], function ($message) {
    $message->to('foo@example.com', 'John Smith')->subject('Welcome!');
});

If the override is set to true email is send to another to email address.

Troubleshooting

If composer update --require-dev refuse to install, remove illuminate/* from vendor before the install or just remove vendor and start fresh.