This package provides a convenient and consistent way to send emails from your Laravel application.
$ composer require browner12/mailer
Add the service provider to the providers array in config/app.php
.
'providers' => [
browner12\mailer\MailerServiceProvider::class,
];
You can publish everything at once
php artisan vendor:publish --provider="browner12\mailer\MailerServiceProvider"
or you can publish groups individually.
php artisan vendor:publish --provider="browner12\mailer\MailerServiceProvider" --tag="config"
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.
'default_data' => [
'company' => 'Acme Co',
'email' => 'info@acme.com',
'phone' => '555-123-4567',
],
You may also choose the default directory that new Mailers are created in. By default they go into a Mailers
directory.
'directory' => 'Mailers';
Use Artisan to generate a new mailer.
php artisan make:mailer UserMailer
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.
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.
$mailer = new UserMailer();
$mailer->signup($user)->send();
You may also render the email output.
echo $mailer->signup($user)->view();
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.
$mailer->signup($user)->sendSynchronously();
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email browner12@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.