Skip to content

addgod/laravel-mandrill-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mandrill Templates for Laravel

A way to send mail via mandrills template system.

Installation

Requirements

  • PHP 7.2
  • Laravel 6

You can install the package via composer:

composer require addgod/laravel-mandrill-template

To publish the config file run:

php artisan vendor:publish --provider="Addgod\MandrillTemplate\MandrillTemplateServiceProvider"

Usage

Add your mandrill secret key to your .env file.

MANDRILL_SECRET="YOUR SECRET KEY"

Sending mail

use Addgod\MandrillTemplate\Mandrill\Message;
use Addgod\MandrillTemplate\Mandrill\Template;
use Addgod\MandrillTemplate\Mandrill\Recipient;
use Addgod\MandrillTemplate\Mandrill\Attachment;
use Addgod\MandrillTemplate\Mandrill\Recipient\Type;
use Addgod\MandrillTemplate\MandrillTemplateFacade;
$template = new Template('template-name');
$message = new Message();
$message
    ->setSubject('Subjct')
    ->setFromEmail('[email protected]')
    ->setFromName('Example Name')
    ->setMergeVars(['greeting' => 'Hello to you']);

$message->addRecipient(new Recipient('[email protected]', 'Example Name', Type::TO));
$message->addAttachment(Attachment::createFromFile($file, 'name_of_file');

MandrillTemplateFacade::send($template, $message);

Via notifications

Create a new notification

php artisan make:notification WelcomeNotification

Set via to MandrillTemplateChannel:

use Addgod\MandrillTemplate\MandrillTemplateChannel;
/**
 * Get the notification's delivery channels.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function via($notifiable)
{
    return [MandrillTemplateChannel::class];
}

Implement toMandrillTemplate method and prepare your template:

use Addgod\MandrillTemplate\MandrillTemplateMessage;
public function toMandrillTemplate($notifiable)
{
    return (new MandrillTemplateMessage)
        ->template('notification')
        ->from('[email protected]', 'Example dot com')
        ->to('[email protected]', 'Frank Kornell') // This is an extra to, since the notifiable is also used.
        ->cc('[email protected]', 'Charlott Kornell')
        ->bcc('[email protected]', 'Mr admin Dude')
        ->greeting('Hello there'),
        ->line('The introduction to the notification.')
        ->action('Notification Action', url('/'))
        ->line('Thank you for using our application!')
        ->salutation('Regards from us.')
        ->attach($file, 'name_of_file);
}

About

A way to send mail via mandrills template system.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages