PHPackages                             loots-it/laravel-mail-template-channel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. loots-it/laravel-mail-template-channel

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

loots-it/laravel-mail-template-channel
======================================

An alternative for the standard mail channel that uses an external template for its content. An example of such a service that provides such templates is Mailjet, for which the implementation is provided.

v1.0.0-beta(5y ago)025MITPHP

Since Oct 26Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Loots-it/laravel-mail-template-channel)[ Packagist](https://packagist.org/packages/loots-it/laravel-mail-template-channel)[ RSS](/packages/loots-it-laravel-mail-template-channel/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (3)Used By (0)

 [ ![Total Downloads](https://camo.githubusercontent.com/6470b592abb552784ab169328f135dbf974713df05c284df370ee2d05004fe6c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6f6f74732d69742f6c61726176656c2d6d61696c2d74656d706c6174652d6368616e6e656c) ](https://packagist.org/packages/loots-it/laravel-mail-template-channel) [ ![Latest Stable Version](https://camo.githubusercontent.com/199cf0562066c7f8a2660cee43b130ecbd46b0b1ef7d37b689dc9480632a224b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6f6f74732d69742f6c61726176656c2d6d61696c2d74656d706c6174652d6368616e6e656c) ](https://packagist.org/packages/loots-it/laravel-mail-template-channel) [ ![License](https://camo.githubusercontent.com/d8fabdc7920e358d258af8eabb7d31e8181605110197b757d758db9d2a25a6b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6f6f74732d69742f6c61726176656c2d6d61696c2d74656d706c6174652d6368616e6e656c) ](https://packagist.org/packages/loots-it/laravel-mail-template-channel)

Installation
------------

[](#installation)

First, include the package with composer:

```
composer require loots-it/laravel-mail-template-channel

```

The most important Provider is the MailTemplateDriverServiceProvider and it's auto discovered via the composer.json file.

The other Provider is TestMailTemplateChannelServiceProvider which adds an Artisan command to test your MailTemplateDriver configuration. If you want to use it, you will need to add it manually to **config/app.php**.

- The providers array:

```
'providers' => [
    ...
    LootsIt\LaravelMailTemplateChannel\Providers\TestMailTemplateChannelServiceProvider::class,
    LootsIt\LaravelMailTemplateChannel\Providers\MailTemplateDriverServiceProvider::class, // This one is auto discovered
    ...
],
```

Configuration
-------------

[](#configuration)

Add the Mailjet API key/secret in your **.env** file:

```
MAILJET_APIKEY=YOUR_APIKEY
MAILJET_APISECRET=YOUR_APISECRET
```

Your API key / secret can be found [here](https://app.mailjet.com/account/api_keys).

Add the following section to the **config/services.php** file:

```
'mailjet' => [
    'key' => env('MAILJET_APIKEY'),
    'secret' => env('MAILJET_APISECRET'),
],
```

If you want to send emails via notifications without specifying the sender email/name in the notification, you will have to add a default sender. To do this, you will first have to publish the config file:

```
php artisan vendor:publish --provider="LootsIt\LaravelMailTemplateChannel\Providers\MailTemplateDriverServiceProvider"

```

Then you have to add a default sender email address and default sender name:

```
return [
    'from' => [
        'email' => 'info@yourdomain.com',
        'name' => 'yourdomain.com',
    ],
];
```

Test configuration
------------------

[](#test-configuration)

You can test your configuration of the mail template Driver/Channel using the command provided by the TestMailTemplateChannelServiceProvider. You will need a template that doesn't need any variables and pass the id (in this example 1) to the command:

```
php artisan mailTemplateDriver:test 1

```

This won't actually send an email, it will only test the configuration.

Usage
-----

[](#usage)

You can use this Channel for any Notification. As an example, I will create a minimal Notification here:

```
php artisan make:notification VerifyEmailNotification

```

You can delete the standard **toMail($notifiable)** method if you want. You should change the **via($notifiable)**method and implement the **toExternalMailTemplate($notifiable)** like below:

```
