PHPackages                             coconutcraig/laravel-postmark - 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. coconutcraig/laravel-postmark

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

coconutcraig/laravel-postmark
=============================

Laravel package for sending mail via the Postmark API

v3.4.1(2mo ago)2152.9M—2.7%311MITPHPPHP ^8.1CI passing

Since Jan 29Pushed 2mo ago6 watchersCompare

[ Source](https://github.com/craigpaul/laravel-postmark)[ Packagist](https://packagist.org/packages/coconutcraig/laravel-postmark)[ Docs](https://github.com/craigpaul/laravel-postmark)[ GitHub Sponsors](https://github.com/mvdnbrk)[ RSS](/packages/coconutcraig-laravel-postmark/feed)WikiDiscussions 3.x Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (78)Used By (1)

[![Postmark](https://camo.githubusercontent.com/bc1bd67d420c959e59946436cc159be4443e56c4620a1287d9b1c49748a982d6/68747470733a2f2f706f73746d61726b6170702e636f6d2f696d616765732f6c6f676f2e737667)](https://postmarkapp.com)

Laravel Postmark
================

[](#laravel-postmark)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1780446eef499318389383f9fe0aed1a1b560417f4cd5ac7ccb1688552e2105d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f636f6e757463726169672f6c61726176656c2d706f73746d61726b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/coconutcraig/laravel-postmark)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Tests](https://camo.githubusercontent.com/def76d6b0e43a0e02d31ccee65ca269bad14391cbdbaaa6649c6cde554862895/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f63726169677061756c2f6c61726176656c2d706f73746d61726b2f74657374732f6d61696e3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/craigpaul/laravel-postmark/actions?query=workflow%3Atests)[![StyleCI](https://camo.githubusercontent.com/93171550559211caae96e95de313be84a059f8afbe60ebf3e87f91811504d830/68747470733a2f2f7374796c6563692e696f2f7265706f732f38303335313834372f736869656c643f6272616e63683d6d61696e)](https://styleci.io/repos/80351847)[![Total Downloads](https://camo.githubusercontent.com/743b95ebdb16d7598c9e9c2cb2a4d8b14e650bd963d9163434b1fb159a7bd883/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f636f6e757463726169672f6c61726176656c2d706f73746d61726b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/coconutcraig/laravel-postmark)

> [Postmark](https://postmarkapp.com) is the easiest and most reliable way to be sure your important transactional emails get to your customer's inbox.

Upgrading
---------

[](#upgrading)

Please see [UPGRADE](UPGRADE.md) for details.

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

[](#installation)

You can install the package via composer:

```
$ composer require coconutcraig/laravel-postmark
```

The package will automatically register itself.

Usage
-----

[](#usage)

Update your `.env` file by adding your server key and set your mail driver to `postmark`.

```
MAIL_MAILER=postmark
POSTMARK_TOKEN=YOUR-SERVER-KEY-HERE
```

That's it! The mail system continues to work the exact same way as before and you can switch out Postmark for any of the pre-packaged Laravel mail drivers (smtp, mailgun, log, etc...).

> Remember, when using Postmark the sending address used in your emails must be a [valid Sender Signature](http://support.postmarkapp.com/category/45-category) that you have already configured.

Postmark Templates
------------------

[](#postmark-templates)

### Notification

[](#notification)

Postmark offers a fantastic templating service for you to utilize instead of maintaining your templates within your Laravel application. If you would like to take advantage of that, this package offers an extension on the base `MailMessage` provided out of the box with Laravel. Within a Laravel notification, you can do the following to start taking advantage of Postmark templates.

```
use CraigPaul\Mail\TemplatedMailMessage;

public function toMail($notifiable)
{
    return (new TemplatedMailMessage)
        ->identifier(8675309)
        ->include([
            'name' => 'Customer Name',
            'action_url' => 'https://example.com/login',
        ]);
}
```

### Mailable

[](#mailable)

It is also possible to use templated notifications via an extension on the base `Mailable` provided out of the box with Laravel.

```
use CraigPaul\Mail\TemplatedMailable;
use Illuminate\Support\Facades\Mail;

$mailable = (new TemplatedMailable())
    ->identifier(8675309)
    ->include([
        'name' => 'Customer Name',
        'action_url' => 'https://example.com/login',
    ]);

Mail::to('mail@example.com')->send($mailable);
```

> You may also utilize an alias instead of the template identifier by using the `->alias()` method in both cases.

Postmark Tags
-------------

[](#postmark-tags)

If you rely on categorizing your outgoing emails using Tags in Postmark, you can simply add a header within your Mailable class's build method.

```
use Symfony\Component\Mailer\Header\TagHeader;
use Symfony\Component\Mime\Email;

public function build()
{
    $this->withSymfonyMessage(function (Email $message) {
        $message->getHeaders()->add(new TagHeader('value'))
    });
}
```

Postmark Metadata
-----------------

[](#postmark-metadata)

Similar to tags, you can also include [metadata](https://postmarkapp.com/support/article/1125-custom-metadata-faq) by adding a header.

```
use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mime\Email;

public function build()
{
    $this->withSymfonyMessage(function (Email $message) {
        $message->getHeaders()->add(new MetadataHeader('field', 'value'));
        $message->getHeaders()->add(new MetadataHeader('another-field', 'another value'));
    });
}
```

In this case, the following object will be sent to Postmark as metadata.

```
{
    "field": "value",
    "another-field", "another value"
}

```

Capture Postmark MessageID
--------------------------

[](#capture-postmark-messageid)

The Postmark API returns a message ID which can be used to query message delivery status

To capture this data setup an event listener

app/Listeners/MessageSentListener.php

```
