PHPackages                             mailersend/laravel-driver - 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. mailersend/laravel-driver

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

mailersend/laravel-driver
=========================

MailerSend Laravel Driver

v3.1.0(2mo ago)87732.8k—3.8%24[3 issues](https://github.com/mailersend/mailersend-laravel-driver/issues)3MITPHPPHP &gt;=8.2CI passing

Since Aug 12Pushed 2mo ago4 watchersCompare

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

READMEChangelog (10)Dependencies (14)Versions (46)Used By (3)

[![](https://camo.githubusercontent.com/0feba5e88bb82404f190f6c877d7ecaf9c17f0b0ffe4f7fb82928bae60104ed7/68747470733a2f2f7777772e6d61696c657273656e642e636f6d2f696d616765732f6c6f676f2e737667)](https://www.mailersend.com)

MailerSend Laravel Driver

[![MIT licensed](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](./LICENSE.md)

Table of Contents
=================

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
- [Support and Feedback](#support-and-feedback)
- [License](#license)

Installation
============

[](#installation)

Requirements
------------

[](#requirements)

- Laravel 10.0+
- PHP 8.2+
- Guzzle 7.0+
- An API Key from [mailersend.com](https://www.mailersend.com)

**For PHP 8.0/8.1 support, see [2.x branch](https://github.com/mailersend/mailersend-laravel-driver/tree/2.x)**

**For Laravel 7.x - 8.x support see [1.x branch](https://github.com/mailersend/mailersend-laravel-driver/tree/1.x)**

Setup
-----

[](#setup)

You can install the package via composer:

```
composer require mailersend/laravel-driver
```

After that, you need to set `MAILERSEND_API_KEY` in your `.env` file:

```
MAILERSEND_API_KEY=
```

Add MailerSend as a Laravel Mailer in `config/mail.php` in `mailers` array:

```
'mailersend' => [
    'transport' => 'mailersend',
],
```

And set environment variable `MAIL_MAILER` in your `.env` file

```
MAIL_MAILER=mailersend
```

Also, double check that your `FROM` data is filled in `.env`:

```
MAIL_FROM_ADDRESS=app@yourdomain.com
MAIL_FROM_NAME="App Name"
```

Usage
=====

[](#usage)

### Old Syntax:

[](#old-syntax)

This is an example using the build [mailable](https://laravel.com/docs/8.x/mail#writing-mailables) that you can use to send an email with.

`app/Mail/TestEmail.php`

```
namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Arr;
use MailerSend\Helpers\Builder\Variable;
use MailerSend\Helpers\Builder\Personalization;
use MailerSend\LaravelDriver\MailerSendTrait;

class TestEmail extends Mailable
{
    use Queueable, SerializesModels, MailerSendTrait;

    public function build()
    {
        // Recipient for use with variables and/or personalization
        $to = Arr::get($this->to, '0.address');

        return $this
            ->view('emails.test_html')
            ->text('emails.test_text')
            ->attachFromStorageDisk('public', 'example.png')
            // Additional options for MailerSend API features
            ->mailersend(
                template_id: null,
                tags: ['tag'],
                personalization: [
                    new Personalization($to, [
                        'var' => 'variable',
                        'number' => 123,
                        'object' => [
                            'key' => 'object-value'
                        ],
                        'objectCollection' => [
                            [
                                'name' => 'John'
                            ],
                            [
                                'name' => 'Patrick'
                            ]
                        ],
                    ])
                ],
                precedenceBulkHeader: true,
                sendAt: new Carbon('2022-01-28 11:53:20'),
            );
    }
}
```

### New Syntax:

[](#new-syntax)

This is an example using the new [mailable](https://laravel.com/docs/9.x/mail#writing-mailables) syntax that you can use to send an email with.

`app/Mail/TestEmail.php`

```
