Coder Social home page Coder Social logo

laravel-mandrill-template's Introduction

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);
}

laravel-mandrill-template's People

Contributors

addgod avatar pendolf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.