danielkellyio/mailgun-mailable

A trait to make your laravel mailables smarter about working with mailgun

1.0.4 2021-04-25 18:00 UTC

This package is auto-updated.

Last update: 2024-03-26 00:08:01 UTC


README

A trait to make your laravel mailables smarter about working with mailgun.

Note - not used to send your mail with Mailgun. Use with mail that's already being sent with Mailgun using Laravel's out of the box Mailgun driver. Provides some helper methods to deal with unique Mailgun features like variables and tags.

Installation

composer require danielkellyio/mailgun-mailable

Add tags to an email

What are mailgun tags?

<?php
use DanielKellyIO\MailgunMailable\MailgunMailable;
// ...

class YourEmail extends Mailable {
	use MailgunMailable;

	public function build() {
		$this->tags(['tag-1', 'tag-2']);
		// ...
	}
}

Add variables to an email

(Can be used to manage email templates within the Mailgun interface. More info)

<?php
use DanielKellyIO\MailgunMailable\MailgunMailable;
// ...

class YourEmail extends Mailable {
	use MailgunMailable;

	public function build() {
        $this->variables([
            'greeting' => 'Hello',
            'name' => 'Daniel'
        ]);
		// ...
	}
}

No mailable class?

Using send with a callback to compose message? Add tags and variables directly to messages like so:

use DanielKellyIO\MailgunMailable\MailgunHelpers;

Mail::send( 'your-email-template', [], function ( $m ) {
    $m->to( 'test@test.com' )->subject( 'Test Email' );
    MailgunHelpers::tags($m, ['tag-1', 'tag-2']);
    MailgunHelpers::variables($m, [
        'greeting' => 'Hello',
        'name' => 'Daniel'
    ]);
});