Mailer
![Software License][ico-license]
![Coverage Status][ico-scrutinizer]
![Total Downloads][ico-downloads], (*1)
This package provides a convenient and consistent way to send emails from your Laravel application., (*2)
Install
``` bash
$ composer require browner12/mailer, (*3)
## Setup
Add the service provider to the providers array in `config/app.php`.
``` php
'providers' => [
browner12\mailer\MailerServiceProvider::class,
];
Publishing
You can publish everything at once, (*4)
``` php
php artisan vendor:publish --provider="browner12\mailer\MailerServiceProvider", (*5)
or you can publish groups individually.
``` php
php artisan vendor:publish --provider="browner12\mailer\MailerServiceProvider" --tag="config"
Configuration
In your mailer.php configuration file, you may set the global data for your mailers. These are often variables that appear in your templates, such as a company name, email, or phone number. This default data will be merged with any data you pass in to a specific mailer., (*6)
``` php
'default_data' => [
'company' => 'Acme Co',
'email' => 'info@acme.com',
'phone' => '555-123-4567',
],, (*7)
You may also choose the default directory that new Mailers are created in. By default they go into a `Mailers` directory.
``` php
'directory' => 'Mailers';
Usage
Use Artisan to generate a new mailer., (*8)
``` sh
php artisan make:mailer UserMailer, (*9)
Create a method within your mailer for every unique email. The following method will be used to send a confirmation email when a user signs up.
``` php
method signup($user)
{
$this->name = $user->name;
$this->email = $user->email;
$this->subject = 'Signup Confirmation';
$this->view = 'emails/signup';
$this->data = [
'user' => $user,
];
return $this;
}
To use the mailer, start by instantiating it. Next, setup the email by calling the method of the email you wish to send. If your method requires parameters, pass them in. Finally, chain the send() method to send the email., (*10)
``` php
$mailer = new UserMailer();, (*11)
$mailer->signup($user)->send();, (*12)
You may also render the email output.
``` php
echo $mailer->signup($user)->view();
Queuing
By default, emails will be sent using Laravel's queueOn() method. Assuming you have queueing setup in your application, this will add the emails to an 'email' queue. To send out emails synchronously, call sendSynchronously() instead., (*13)
``` php
$mailer->signup($user)->sendSynchronously();, (*14)
## Change log
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Testing
``` bash
$ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details., (*15)
Security
If you discover any security related issues, please email browner12@gmail.com instead of using the issue tracker., (*16)
Credits
License
The MIT License (MIT). Please see License File for more information., (*17)