2017 © Pedro Peláez
 

library pigeon

A more flexible email message builder for Laravel 5 including chained methods, reusable message configurations, and message layout and template view management.

image

larablocks/pigeon

A more flexible email message builder for Laravel 5 including chained methods, reusable message configurations, and message layout and template view management.

  • Friday, May 19, 2017
  • by emitkowski
  • Repository
  • 1 Watchers
  • 10 Stars
  • 1,197 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 16 Versions
  • 11 % Grown

The README.md

Pigeon

Build Status Latest Stable Version License, (*1)

A more flexible email message builder for Laravel 5 including chained methods, reusable message type configurations, and email layout and template view management., (*2)

Note: All Larablocks packages will have releases in line with the major Laravel framework version release. (Ex. Pigeon 5.4.* is tested to work with Laravel 5.4.* while Pigeon 5.1.* is tested to worked with Laravel 5.1.*), (*3)

Installation

Add larablocks/pigeon as a requirement to composer.json:, (*4)

{
    "require": {
        "larablocks/pigeon": "~5.4"
    }
}

Update your packages with composer update or install with composer install., (*5)

Laravel Integration

To wire this up in your Laravel project you need to add the service provider. Open app.php, and add a new item to the providers array., (*6)

Larablocks\Pigeon\PigeonServiceProvider::class,

Then you may add a Facade for more convenient usage. In your app.php config file add the following line to the aliases array., (*7)

'Pigeon' => Larablocks\Pigeon\Pigeon::class,

Note: The Pigeon facade will load automatically, so you don't have to add it to the app.php file but you may still want to keep record of the alias., (*8)

To publish the default config file config/pigeon.php along with the default email view files use the artisan command:, (*9)

php artisan vendor:publish --provider="Larablocks\Pigeon\PigeonServiceProvider", (*10)

If you wish to not publish the view files and only publish the config then use the artisan command:, (*11)

php artisan vendor:publish --provider="Larablocks\Pigeon\PigeonServiceProvider" --tag="config", (*12)

Usage as a Facade

Pigeon::

Setting the General Message Properties

Pigeon will load all properties set in the default area of your config before you construct your message., (*13)

Set message addresses:

All these address add methods can be used with any of the address add functions (to, cc, bcc, replyTo, from, sender), (*14)

Add a single address with no name, (*15)

Pigeon::to('john.doe@domain.com') 
Pigeon::cc('john.doe@domain.com') 
Pigeon::bcc('john.doe@domain.com') 
Pigeon::replyTo('john.doe@domain.com') 
Pigeon::from('john.doe@domain.com') 
Pigeon::sender('john.doe@domain.com') 

Add a single address with name, (*16)

Pigeon::to('john.doe@domain.com', 'John Doe')
....

Add array of addresses with no names, (*17)

Pigeon::to(['john.doe@domain.com', 'jane.doe@domain.com']) 
...

Add array of addresses some with names, some without names, (*18)

Pigeon::to(['john.doe@domain.com' => 'John Doe', 'jane.doe@domain.com']) 
...

Set Subject:

Pigeon::subject('My Subject') 

File Attachments:

Attach a single file with no options, (*19)

Pigeon::attach('/path/to/file/attachment')

Attach a single file with options, (*20)

Pigeon::attach('/path/to/file/attachment', ['as' => 'Attachment', 'mime' => 'jpg'])

Attach an array of files, (*21)

Pigeon::attach([
    [
     'path' => '/path/to/file/attachment1'
     'options' => []
    ],
    [
     'path' => '/path/to/file/attachment2'
     'options' => ['as' => 'Attachment 2', 'mime' => 'pdf']
    ]
])

Setting the Message View Properties

Set layout view file:

Pigeon::layout('emails.layouts.my_layout_view')

Set template view file:

Pigeon::template('emails.templates.my_template_view')

Passing View Variables:

Passing simple variables:, (*22)

Pigeon::pass([
 'stringVariable' => 'test string', 
 'intVariable' => 2, 
 'boolVariable' => true
])

Passing object variables:, (*23)

$user = new User();
$user->first_name = 'John';
$user->last_name = 'Doe';
Pigeon::pass([
 'userObjectVariable' => $user
])

If pass() is used more than once it will merge previously passed variables with the current passed set., (*24)

Note: Make sure all variables pre-defined in your layout and template view files are passed to your Pigeon message., (*25)

Clearing View Variables:

Clear all previously passed view variables, (*26)

Pigeon::clear()

Custom Messages Types

Custom message types will be configured in the config/pigeon.php file. In this file you can find examples on how to properly set up a custom message type., (*27)

Default:

Set your defaults for all messages sent with Pigeon in config\pigeon.php, (*28)

'default' => [
    'to' => [],
    'cc' => [],
    'bcc' => [],
    'replyTo' => [],
    'from' => [], // if nothing is entered here, your mail.php default will still be used
    'sender' => [],
    'attachments' => [],
    'subject' => 'Pigeon Delivery',
    'layout' => 'emails.layouts.default',
    'template' => 'emails.templates.default',
    'message_variables' => []
]

Load Custom Message:

Set your defaults for a particular message type to be sent with Pigeon in config\pigeon.php, (*29)

'custom_message_type' => [
    'from' => ['from@myapp.com' => 'My Custom App'],
    'subject' => 'My Pigeon Custom Message',
    'layout' => 'emails.layouts.default',
    'template' => 'emails.templates.default'
]

This will load all the message properties from your config defined for custom_message_type., (*30)

Pigeon::type('custom_message_type');

Order of Loading:

Default -> Custom Message (if set and loaded) -> Properties set with individual Pigeon functions, (*31)

Sending the Message

Send Message:

Pigeon::send();

Send Raw Message:

Pass a string as a param for the send() function and it will use the string as a raw message send and will ignore any view files or view variables assigned., (*32)

Pigeon::send('This is my raw message');

Example - Using it all together

Pigeon::to(['john.doe@domain.com', 'jane.doe@domain.com'])
->cc('fred.doe@domain.com')
->bcc('george.doe@domain.com')
->subject('This is the Subject')
->attach('/path/to/file/attachment')
->layout('emails.layouts.my_layout_view')
->template('emails.templates.my_template_view')
->pass(['firstVariable' => 'test string', 'secondVariable' => 2, 'thirdVariable' => true])
->send();

Example - Simple call

Pigeon::to('me@domain.com')->subject('Testing Pigeon')->send('Sending myself a quick raw message');

Example - Sending a custom message

Pigeon::type('custom_message_type')->to('me@domain.com')->send();

Usage as a Passed Dependency

To pass Pigeon as a dependency will will pass the interface Larablocks\Pigeon\PigeonInterface. For now the only library that implements this interface is Larablocks\Pigeon\IlluminateMailer provided by Laravel but we want to allow for other mailing libraries to be used in the future. The config/pigeon.php config file for Pigeon automatically sets IlluminateMailer as the default mailer library for you., (*33)

'library' => 'IlluminateMailer',

Passing Pigeon to a constructor:

public function __construct(Larablocks\Pigeon\PigeonInterface $pigeon) 
{
$this->pigeon = $pigeon;
}

Starting a new default message:

$this->pigeon->to('me@domain.com')->subject('Pigeon Raw Test Message')->send('Sending myself a quick raw message');

Starting a new custom message type:

$this->pigeon->type('custom_message_type')->to('me@domain.com')->send();

License

Pigeon is open-sourced software licensed under the MIT license, (*34)

The Versions

19/05 2017

dev-master

9999999-dev

A more flexible email message builder for Laravel 5 including chained methods, reusable message configurations, and message layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer message laravel 5 views builder 5.1 5.2 pigeon

19/05 2017

5.4.2

5.4.2.0

A more flexible email message builder for Laravel 5 including chained methods, reusable message configurations, and message layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer message laravel 5 views builder pigeon

13/05 2017

5.4.1

5.4.1.0

A more flexible email message builder for Laravel 5 including chained methods, reusable message configurations, and message layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer message laravel 5 views builder pigeon

13/05 2017

5.4.0

5.4.0.0

A more flexible email message builder for Laravel 5 including chained methods, reusable message configurations, and message layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer message laravel 5 views builder pigeon

04/02 2016

5.2.2

5.2.2.0

A more flexible email message builder for Laravel 5.2 and 5.1 including chained methods, reusable message configurations, and message layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer message views builder 5.1 5.2 pigeon

04/02 2016

5.2.1

5.2.1.0

A more flexible email message builder for Laravel 5.2 and 5.1 including chained methods, reusable message configurations, and message layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer message views builder 5.1 5.2 pigeon

04/02 2016

5.1.x-dev

5.1.9999999.9999999-dev

A more flexible email message builder for Laravel 5.0 and 5.1 including chained methods, reusable message configurations, and message layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer message views builder 5.1 pigeon

04/02 2016

5.2.0

5.2.0.0

A more flexible email message builder for Laravel 5.2 and 5.1 including chained methods, reusable message configurations, and message layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer message views builder 5.1 5.2 pigeon

11/01 2016

5.1.2

5.1.2.0

A more flexible email message builder for Laravel 5.0 and 5.1 including chained methods, reusable message configurations, and message layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer message views builder 5.1 pigeon

09/06 2015

5.1.1

5.1.1.0

A more flexible email message builder for Laravel 5.0 and 5.1 including chained methods, reusable message configurations, and message layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer message views builder 5.1 pigeon

09/06 2015

5.0.x-dev

5.0.9999999.9999999-dev

A more flexible email message builder for Laravel 5 including chained methods, reusable message type configurations, and email layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer blade message views builder pigeon

09/06 2015

5.1.0

5.1.0.0

A more flexible email message builder for Laravel 5.0 and 5.1 including chained methods, reusable message configurations, and message layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer message views builder 5.1 pigeon

01/06 2015

5.0.0

5.0.0.0

A more flexible email message builder for Laravel 5 including chained methods, reusable message type configurations, and email layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer blade message views builder pigeon

15/05 2015

0.2.1

0.2.1.0

A more flexible email message builder for Laravel 5 including chained methods, reusable message type configurations, and email layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer blade message views builder pigeon

14/05 2015

0.2

0.2.0.0

A more flexible email message builder for Laravel 5 including chained methods, reusable message type configurations, and email layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer blade message views builder pigeon

12/05 2015

0.1

0.1.0.0

A more flexible email message builder for Laravel 5 including chained methods, reusable message type configurations, and email layout and template view management.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eric Mitkowski

laravel mail email template mailer blade message views builder pigeon