PHPackages                             seinoxygen/laravel-elastic-email - 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. seinoxygen/laravel-elastic-email

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

seinoxygen/laravel-elastic-email
================================

A Laravel wrapper for Elastic Email

v1.0.5(2y ago)1179MITPHPPHP ^7.1|^8.0

Since Oct 20Pushed 2y ago1 watchersCompare

[ Source](https://github.com/seinoxygen/laravel-elastic-email)[ Packagist](https://packagist.org/packages/seinoxygen/laravel-elastic-email)[ RSS](/packages/seinoxygen-laravel-elastic-email/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (7)Used By (0)

Laravel Elastic Email
=====================

[](#laravel-elastic-email)

[![Donate](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.com/donate/?hosted_button_id=6CYVR8U4VDMAA) [![Packagist Downloads](https://camo.githubusercontent.com/e9cb4f3da6fdcd729e8ef024a4e684836f0a237354830f4aea22c553c112447f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7365696e6f787967656e2f6c61726176656c2d656c61737469632d656d61696c3f6c6162656c3d446f776e6c6f616473)](https://camo.githubusercontent.com/e9cb4f3da6fdcd729e8ef024a4e684836f0a237354830f4aea22c553c112447f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7365696e6f787967656e2f6c61726176656c2d656c61737469632d656d61696c3f6c6162656c3d446f776e6c6f616473) [![GitHub](https://camo.githubusercontent.com/439bbfd9a65794d6c69687a8628f0b2e40bdfecfef3efc6babff847b307769cb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7365696e6f787967656e2f6c61726176656c2d656c61737469632d656d61696c3f6c6162656c3d4c6963656e7365)](https://camo.githubusercontent.com/439bbfd9a65794d6c69687a8628f0b2e40bdfecfef3efc6babff847b307769cb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7365696e6f787967656e2f6c61726176656c2d656c61737469632d656d61696c3f6c6162656c3d4c6963656e7365) [![CodeFactor Grade](https://camo.githubusercontent.com/810ec7f546d84af89b45261e0c69ecd6cae038ee2bc622b774f23b44e6351808/68747470733a2f2f696d672e736869656c64732e696f2f636f6465666163746f722f67726164652f6769746875622f7365696e6f787967656e2f6c61726176656c2d656c61737469632d656d61696c3f6c6162656c3d5175616c697479)](https://camo.githubusercontent.com/810ec7f546d84af89b45261e0c69ecd6cae038ee2bc622b774f23b44e6351808/68747470733a2f2f696d672e736869656c64732e696f2f636f6465666163746f722f67726164652f6769746875622f7365696e6f787967656e2f6c61726176656c2d656c61737469632d656d61696c3f6c6162656c3d5175616c697479)

A Laravel wrapper for sending emails via Elastic Email service and API capabilities that allows you to check the status of every email sent. It provides a basic email log table to store all outbound emails where you can link to a model.

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

[](#installation)

Add Laravel Elastic Email as a dependency using the composer CLI:

```
composer require seinoxygen/laravel-elastic-email
```

Mail Service Usage
------------------

[](#mail-service-usage)

This package works exactly like Laravel's native mailers. Refer to Laravel's Mail documentation.

Add the following to your config/services.php and add the correct values to your .env file

```
'elastic_email' => [
	'key' => env('ELASTIC_KEY'),
	'account' => env('ELASTIC_ACCOUNT')
]
```

Add the following to your config/mail.php

```
'elastic_email' => [
	'transport' => 'elasticemail'
]
```

Next, in config/app.php, comment out Laravel's default MailServiceProvider. If using &lt; Laravel 5.5, add the MailServiceProvider and ApiServiceProvider to the providers array

```
'providers' => [
    ...
    SeinOxygen\ElasticEmail\MailServiceProvider::class,
    SeinOxygen\ElasticEmail\ApiServiceProvider::class,
    ...
],
```

Next, in config/app.php, add the ElasticEmail to the aliases array

```
'aliases' => [
    ...
    'ElasticEmail' => SeinOxygen\ElasticEmail\Facades\ElasticEmail::class,
    ...
],
```

Finally switch your default mail provider to elastic email in your .env file by setting **MAIL\_DRIVER=elastic\_email**

Outbound Email Tracking
-----------------------

[](#outbound-email-tracking)

To keep track of all emails sent by the driver you'll need to publish the migrations and the configuration files:

```
php artisan vendor:publish --provider="SeinOxygen\ElasticEmail\ApiServiceProvider" --tag="migrations"
```

```
php artisan migrate
```

```
php artisan vendor:publish --provider="SeinOxygen\ElasticEmail\ApiServiceProvider" --tag="config"
```

By default all outgoing emails will be stored with the Elastic Email **message\_id** and **transaction\_id**.

Check **config/elasticemail.php** for more options.

### Linking Outgoing Emails To Your Models

[](#linking-outgoing-emails-to-your-models)

In your mailable be sure to set the with array the following way.

```
public function build()
{
    // You can set ad many models you want to relate with the outgoing email
    $models = [
        [$yourmodel->id, get_class($yourmodel)],
    ];

    return $this
        ->subject("My Subject")
        ->view('my-view')
        ->with([
            'models' => $models
        ]);
}
```

Sorry if it looks ugly. I haven't found a better way to do this...yet.

### Capturing Webhook Events

[](#capturing-webhook-events)

You will need to set a webhook in Elastic Email service pointing to **yourappurl.com/webhook/elasticemail**

There is an event being fired when data is sent to the webhook url.

```
