Search by

beebmx / kirby-courier

beebmx

Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.

Package info

github.com/beebmx/kirby-courier

Type:kirby-plugin

pkg:composer/beebmx/kirby-courier

Fund package maintenance!

beebmx

Statistics

Installs: 5 874

Dependents: 1

Suggesters: 0

Stars: 40

Open Issues: 0

2.2.0 2026-11-29 01:15 UTC

This package is auto-updated.

Last update: 2026-11-29 01:17:29 UTC


README

Kirby Courier Logo

Build Status Total Downloads Latest Stable Version License

Courier for Kirby

Courier offers a convenient and painless solution for creating emails tailored for your Kirby website. With Courier, you can streamline the process of email design and implementation for your site.

Overview

Compatibility

Version Kirby 4 Kirby 5 Kirby 6 PHP
2.x ❌ ❌ ✅ 8.4+
1.3 – 1.5 ❌ ✅ ❌ 8.3+
1.1 – 1.2 ❌ ✅ ❌ 8.2+
1.0.4 – 1.0.6 ✅ ✅ ❌ 8.2+
1.0.0 – 1.0.3 ✅ ❌ ❌ 8.2+

Note

Courier 2.x is built for the Vue 3 Panel of Kirby 6 and is tested on PHP 8.4, 8.5 and 8.6. If your site runs Kirby 4 or 5, use Courier 1.x.

Installation

Download

Download and copy this repository to /site/plugins/kirby-courier.

Composer

composer require beebmx/kirby-courier

Usage

Courier comes with two email message types, and you can customize them for your convenience.

Kirby Courier example

Notification message

The Notification message is the easiest way to send an email. You only need to use the Beebmx\KirbyCourier\Notification\Message class in your controller or in your own implementation. Here's an example:

use Beebmx\KirbyCourier\Notification\Message;

(new Message)
    ->to('john@doe.co')
    ->line('Welcome to Kirby Courier')
    ->action('Visit', 'https://beeb.mx')
    ->send()

Formating notification messages

You have several methods to customize your Notification message. Here's an example with all the methods:

use Beebmx\KirbyCourier\Notification\Message;

(new Message)
    ->to('john@doe.co')
    ->greeting('Hello friend!')
    ->line('Welcome to Kirby Courier')
    ->line('You can add more lines before an action')
    ->lines(['Multiple line 01', 'Multiple line 02'])
    ->lineIf($someCondition === true, 'You can add more lines before an action')
    ->linesIf($someCondition === false, ['Line 03', 'Line 04'])
    ->image($page->cover(), caption: 'Our spring collection') // A URL, a file, a field with a file or an asset
    ->details(['Order' => '#1234', 'Total' => '$35.00'], total: true, title: 'Order summary')
    ->imageIf($order->isGift(), $page->file('gift.png'))     // Only when the condition is true
    ->detailsIf($order->hasShipping(), ['Carrier' => 'DHL', 'Tracking' => 'ABC123'])
    ->code('123 456')   // A code, like a two-factor authentication code
    ->success()         // To set the action button as successful
    ->error()           // To set the action button as an error
    ->action('Action button', 'https://beeb.mx')
    ->divider('or')     // A line with an optional label
    ->line('You can add lines after an action')
    ->salutation('Good bye!')
    ->send()

The image, details and divider are shown where you add them between the lines, and they take the same options as their snippets: image($src, $alt, $width, $url, $caption, $align), details($items, $total, $title) and divider($label, $space). Their caption, title and label are escaped like the lines.

Warning

You can only add one action and one code per Notification message.

Mail message

The Mail message is the easiest way to send an email if you need to customize all the body of your email, you only need to use the Beebmx\KirbyCourier\Mail\Message class in your controller or in your own implementation. Here's an example:

use Beebmx\KirbyCourier\Mail\Message;

(new Message)
    ->to('john@doe.co')
    ->template('marketing')
    ->send()

Note

It's important that you set a template to display your own customization. Every template should be located in your courier directory.

Formating mail messages

To create your own template for your mail messages, you need to create a file in the default location for Courier. Here's an example for a marketing message:

/*** /site/template/courier/marketing.php ***/

<?php snippet('courier/message', slots: true) ?>
<?php slot('body') ?>
# Hello Courier

The body of your courier message.

<?php snippet('courier/button', ['url' => ''], slots: true) ?>
Button
<?php endsnippet() ?>

Thanks,
<?= site()->title() ?>
<?php endslot() ?>
<?php endsnippet() ?>

Note

You can add content as markdown and it will be processed by kirbytext.

Preheader

The preheader is the preview text that most inboxes show after the subject. It's hidden in the email body and it's left out of the text version. Set it with the preheader method of the message:

(new Message)
    ->template('marketing')
    ->preheader('Our spring collection is here')
    ->send()

The default templates already pass it to the courier/message snippet; in your own templates pass the preheader variable:

<?php snippet('courier/message', ['logo' => $logo ?? null, 'preheader' => $preheader ?? null], slots: true) ?>

Or write it in the template itself with the preheader slot, which takes precedence over the variable:

<?php snippet('courier/message', slots: true) ?>
<?php slot('preheader') ?>
Our spring collection is here
<?php endslot() ?>
<?php slot('body') ?>
# Hello Courier
<?php endslot() ?>
<?php endsnippet() ?>

Message methods

For both Notifications and Mail messages, there are shared methods. Here's an example with all the methods:

use Beebmx\KirbyCourier\Mail\Message;

(new Message)
    ->preset('contact')                     // The preset should be available in your config.php file
    ->from('no-reply@example.co')
    ->from('no-reply@example.co', 'Webmaster')  // You can add a name to from address
    ->to('john@doe.co')
    ->to('jane@doe.co')                     // You can add multiple recipients (TO)
    ->cc('john@doe.co')
    ->cc('jane@doe.co')                     // You can add multiple recipients (CC)
    ->bcc('john@doe.co')
    ->bcc('jane@doe.co')                    // You can add multiple recipients (BCC)
    ->replyTo('john@doe.co')
    ->subject('Thank you for your contact request')
    ->preheader('We will get back to you soon') // The preview text shown by the inbox after the subject
    ->theme('dark')                         // The theme should be available in your themes
    ->data(['name' => 'John Doe', 'position' => 'CEO']) // All the data available for the template
    ->attach($page->file('image.jpg'))
    ->attach($page->file('file.pdf'))       // You can add multiple files
    ->attachMany([$page->file('file.pdf'), $page->file('file.jpg')])
    ->render()                              // Returns a Content instance to visualize
    ->send()                                // Trigger to send the email

If you want to previsualize your email, you can do it in any template. Here's an example:

<?= (new Beebmx\KirbyCourier\Mail\Message)
    ->template('marketing')
    ->data(['name' => 'John Doe'])
    ->render()
    ->toHtml() ?>

Note

The render method doesn't trigger any email, and doesn't require any email settings like subject, from or to.

Snippets

For your convenience, Courier has some snippets to speed up your email building flow. You can add them in your courier template.

Note

You can create your own snippets if you want and apply it to the courier/message snippet. Just be sure to add it in the slot('body').

Every email is sent with an HTML and a plain text version, so every snippet renders in both. The text version keeps what a text reader needs: the URL after each link (our site (https://example.com)), the bullets of lists, the table columns aligned, panels quoted with >, and an empty line between paragraphs.

Button

<?php snippet('courier/button', ['url' => 'https://example.com', 'color' => 'success', 'align' => 'left'], slots: true) ?>
Button
<?php endsnippet() ?>

The color can be primary (or blue), success (or green) and error (or red), and align can be left, center or right. The button works in Outlook on Windows too, which ignores the padding of links: the cell around the link has the color and the padding for it (mso-padding-alt). On small screens, the button takes the full width.

To add your own color in your theme, style the link and its cell:

.button-brand,
.button-cell-brand {
    background-color: #7c3aed;
}

Code

A code, like a two-factor authentication code: every character is shown in its own box, and a space separates groups. The characters stay together when the code is copied (123456), and the text version shows it as it is:

<?php snippet('courier/code', slots: true) ?>
123 456
<?php endsnippet() ?>

Panel

<?php snippet('courier/panel', slots: true) ?>
This is a panel
<?php endsnippet() ?>

Details

A list of labels and values, like the summary of an order, a receipt or a booking:

<?php snippet('courier/details', ['items' => [
    'Order' => '#1234',
    'Date' => 'November 28, 2026',
    'Shipping' => '$5.00',
    'Total' => '$35.00',
], 'total' => true], slots: true) ?>
Order summary
<?php endsnippet() ?>

The items can be an array of labels and values, a list of pairs to repeat a label ([['Shirt', '$20'], ['Shirt', '$10']]), or a structure field from the Panel with label and value fields ($page->details()->toStructure()). With total, the last row is highlighted as the total. The content of the snippet is the title of the details, and it's optional.

The labels and values are escaped, so they can be user input: markdown keeps working, but HTML is shown as text. The text version aligns the values after the labels:

Order summary

Order:    #1234
Date:     November 28, 2026
Shipping: $5.00
Total:    $35.00

Divider

A horizontal line to separate the sections of your email. Its content is an optional label in the middle of the line, and space sets the space above and below it in pixels (24 by default):

<?php snippet('courier/divider') ?>

<?php snippet('courier/divider', ['space' => 12], slots: true) ?>
or
<?php endsnippet() ?>

The text version shows the line as --- (or --- or ---). The line is drawn with a background color, so it works in Outlook: change it in your theme with .divider-line { background-color: #cbd5e1; }.

Image

The src of the image can be a URL, a file from the Panel (or a field with a file), an asset, or a resized or cropped version of them:

<?php snippet('courier/image', ['src' => $page->cover()]) ?>

<?php snippet('courier/image', ['src' => asset('assets/images/banner.jpg'), 'url' => 'https://example.com/shop', 'width' => 300], slots: true) ?>
Our spring collection
<?php endsnippet() ?>
Option Default Description
src A URL, a File, a Field with a file, an Asset or a version of them
alt The alternative text, files use their alt field when it's not set
width 100% The width in pixels (width="300"), without it the image is fluid
url Links the image to the given URL
align center left, center or right

The content of the snippet is the caption of the image, and it's optional.

Without a width the image is fluid: it takes 100% of the content (files and assets up to their own width, so they aren't stretched) and the file is used as it is. With a width, the image keeps it and only shrinks on small screens, and files and assets are resized to twice that width to look sharp on high density screens. Files and assets are never shown wider than they are.

Warning

Outlook on Windows ignores the CSS width of the images, so a fluid image is shown there with its own width. Set a width to big images to keep them inside the email in Outlook. The text version shows the alternative text (with the URL of the link) and the caption.

The URLs of files and assets are always absolute, because email clients don't show relative images. Kirby knows the domain of your site from its url option or from the current request, so if you send emails from the CLI, a queue or a cron job, set the beebmx.courier.url option (or Kirby's url option):

'beebmx.courier' => [
    'url' => 'https://example.com',
],

Note

The resized images are generated by Kirby the first time they are requested, so your site should be public.

Table

<?php snippet('courier/table', slots: true) ?>
| Content      | Info          | Currency  |
| ------------ | :-----------: | --------: |
| Content 01   | Centered      | $100      |
| Content 02   | Is centered   | $150      |
<?php endsnippet() ?>

Subcopy

<?php snippet('courier/subcopy', slots: true) ?>
This is a subcopy
<?php endsnippet() ?>

Blade

If you prefer Blade over plain PHP templates, Courier works out of the box with Kirby Blade ^7.0:

composer require beebmx/kirby-blade

When Kirby Blade is installed, Courier uses its Blade templates for the default mail and notification messages, and every snippet is available as an anonymous component with the courier prefix:

{{-- /site/templates/courier/marketing.blade.php --}}

<x-courier::message :logo="$logo" :preheader="$preheader ?? null">
# Hello {{ $name }}

The body of your courier message.

<x-courier::button url="https://beeb.mx" color="success">
Button
</x-courier::button>

<x-courier::panel>
This is a panel
</x-courier::panel>

<x-courier::image :src="$page->cover()" url="https://beeb.mx" />

<x-courier::details :items="['Order' => '#1234', 'Total' => '$35.00']" total>
Order summary
</x-courier::details>

Thanks,
{{ site()->title() }}
</x-courier::message>

The available components are message, layout, preheader, header, footer, button, code, details, divider, image, panel, subcopy and table (and element, which renders the image, details and divider of the Notification message). They are rendered as HTML for the email body and as plain text for its text version.

The preheader can also be written in the template with the preheader slot:

<x-courier::message>
<x-slot:preheader>
Our spring collection is here
</x-slot:preheader>

# Hello Courier
</x-courier::message>

Note

Every template is rendered with the elements that match it: *.blade.php templates use the Blade components and *.php templates use the snippets, so you can mix both kinds of templates in the same site.

If Kirby Blade is installed but you want to keep the PHP templates as the default Courier templates, disable its bootstrap in your config.php file:

'beebmx.kirby-blade.bootstrap' => false,

Warning

Kirby Blade requires to disable the Kirby e() helper. Please follow the Kirby Blade installation notes.

Note

On PHP 8.6, Kirby Blade needs illuminate/view ^13.0. Version 12 raises spl_object_hash() deprecations that break the rendering, so update it with composer require illuminate/view:^13.0 if needed.

Console

If you are a Kirby CLI user, Courier also has you covered. The Courier commands can help you create Mail messages faster or even create your own Courier Theme.

You can create your Mail template with:

$ kirby make:courier <template>
$ kirby courier:make <template>

Note

courier:make is an alias of make:courier

To create a Blade template, add the --blade flag:

$ kirby make:courier <template> --blade

Or may be you want to customize your messages with your own theme with:

$ kirby courier:theme <theme>

Tip

Every rule of the theme is inlined on the elements it matches, so prefer rules that are inherited. A rule for every element (body *) is copied to every element of the email, and Gmail clips emails bigger than 102KB. The default theme sets the font only on body and .wrapper; the layout sets it for Outlook on Windows.

Helper

If dealing with namespaces is hard, or you feel confused using the same Message class name, you can simplify it with the courier helper:

For Notification message you can use:

courier('notification')
    ->to('john@doe.co')
    ->line('This is a line')
    ->send()

For Mail message you can use:

courier('mail')
    ->to('john@doe.co')
    ->template('marketing')
    ->send()

And of course, you can use it in a template to render it:

<?= courier('mail')
        ->template('marketing')
        ->render()
        ->toHtml() ?>

Challenge

Courier also provides a challenge message type to help you with your login and password reset flows. The courier challenge works like the Kirby email challenge, but the code is sent with a Courier notification message.

First, you need to set the challenge in your config.php file:

'auth' => [
    'challenges' => ['webauthn', 'totp', 'courier'],
],

Important

Kirby 6 enables the webauthn (passkeys), totp (authenticator app) and email challenges by default. The challenges option replaces that whole list, so 'challenges' => 'courier' or ['courier'] leaves only the code via email: passkeys and the authenticator app are no longer offered for the two-factor authentication. Keep webauthn and totp in the list and replace email with courier.

Note

If you keep email next to courier, the login view offers the code via email twice, and the email one is sent as a plain email.

Then, you can specify the methods you want to use in your config.php file:

'auth' => [
    'challenges' => ['webauthn', 'totp', 'courier'],
    'methods'   => ['password', 'code'],
],

Warning

The courier challenge sends the codes for the code and password-reset methods, and for the two-factor authentication.

Two-factor authentication

The webauthn (passkeys) and totp (authenticator app) challenges work next to the courier challenge. They don't send any email: the passkey or the authenticator app verifies the user.

When a user enables the email two-factor authentication in the Security settings of their account, the confirmation code is sent with a Courier notification message too, as long as the courier challenge is enabled.

Sender

The code emails are sent from the beebmx.courier.from address and name, like every other Courier email. To send them from another address, set the auth.challenge.email options of Kirby:

'auth' => [
    'challenge' => [
        'email' => [
            'from' => 'security@example.com',
            'fromName' => 'Example security',
        ],
    ],
],

Testing email

Courier comes out of the box with a panel area to help you test your email messages and check your email settings.

Choose the email in the header of the area:

Email Description
Sample email A sample of the Courier emails: preheader, lines, details, a button and a divider
Login code (2FA) The login code email of the courier challenge, also sent for the two-factor authentication
Password reset code The password reset code email of the courier challenge
  • Preview shows the email as it would be received, with its sender and subject, in its HTML and text versions. Nothing is sent.
  • Send email sends it to the given address. When it fails, the notification tells why, like the error of the SMTP server.

The code emails use a sample code: no code is created, so it can't be used to log in.

Settings

Below, the area shows the settings that are really used to send the emails, with a warning for the ones that would fail or end up as spam:

Settings Shows
Courier settings The logo, the from name and address, the courier challenge and the sender of the code emails. Warns about the example address, invalid addresses, senders that are not on the domain of the provider, and a courier challenge that is not enabled or is enabled next to email.
Email settings The provider and only its own settings: mail(), SMTP, or Mailgun and Resend with kirby-email-plus.

The SMTP settings show what Kirby really uses, like ssl when the security is not set, or the security detected from the port when it's true. Passwords and API keys are never sent to the Panel, they're only shown as configured or missing.

The Courier challenge row tells if Kirby really sends the login and password reset codes with Courier, as the preview shows them, and how long the codes are valid (the auth.challenge.timeout option). Without the courier challenge in the auth.challenges option, Kirby sends them as a plain email.

With a local SMTP server (localhost, 127.0.0.1, ::1, or a .test, .local or .ddev.site host, like the one of Herd, Mailpit or DDEV), or a site in local development, both detected like Kirby does it, the missing credentials and the domain of the senders are not a warning.

You can change the label and icon from the config.php file.

'beebmx.courier' => [
    'panel' => [
        'label' => 'Testing',
        'icon' => 'wand',
    ],
],

Note

If you change the icon, be sure to use an available Kirby Panel icon from the official list.

If you only want to enable the testing area for specific user roles, you can do it with the roles option:

#bluprints/users/editor.yml

permissions:
  access:
    courier: false

If this option is not for you or all your users, you can disable it completely with:

'beebmx.courier' => [
    'panel' => false
],

Note

The same rules protect the API routes that preview and send the test email: they only work for logged-in users with access to the courier area, and they're disabled together with the panel option.

Escaping

The values of the Notification message (greeting, line, code, action and salutation, and the caption, title, label and items of its image, details and divider) are escaped, so it's safe to add user input like a contact form message. Markdown keeps working, but HTML is shown as text. The labels and values of the details snippet are escaped too. To escape your own values the same way, use Beebmx\KirbyCourier\Markdown::escape($value).

If you need HTML in your message, create a Mail message with your own template.

Options

Option Type Default Description
beebmx.courier.logo Closure,string,null null Set your own logo in every message.
beebmx.courier.url string,null null The base for the URLs of files and assets when Kirby doesn't know the domain (CLI, queues).
beebmx.courier.path string courier Set a path where the templates and themes are located.
beebmx.courier.from.address string hello@example.com Set the default from.address for every message.
beebmx.courier.from.name string Example Set the default from.name for every message.
beebmx.courier.message.greeting string Hello! Set the default message.greeting for every message.
beebmx.courier.message.rights string All rights reserved. Set the default message.rights for every message.
beebmx.courier.message.salutation string Regards Set the default message.salutation for every message.
beebmx.courier.message.subject string Message from courier Set the default message.subject for every message.
beebmx.courier.message.notify string Set the default message.notify for every message.
beebmx.courier.message.brand_name ?string null Set the default message.brand_name for every message.
beebmx.courier.challenge.theme ?string default Set the default theme for your challenge message.
beebmx.courier.challenge.greeting ?string null Set the greeting message for your challenge.
beebmx.courier.challenge.email.login.before ?string null Set the text before code for login message.
beebmx.courier.challenge.email.login.after ?string null Set the text after code for login message.
beebmx.courier.challenge.email.password-reset.before ?string null Set the text before code for password-reset message.
beebmx.courier.challenge.email.password-reset.after ?string null Set the text after code for password-reset message.
beebmx.courier.panel array,false Set false to disable the panel area.
beebmx.courier.panel.label string Courier Set the label of the panel area.
beebmx.courier.panel.icon string email Set the icon of the panel area.

Here's an example of a full use of the options from the config.php file:

'beebmx.courier' => [
    'logo' => function() {
        return site()->file('logo.png'); // or an asset, a URL or a files field: site()->logo()
    },
    'url' => 'https://example.com',
    'path' => 'courier',
    'from' => [
        'address' => 'hello@example.com',
        'name' => 'Example',
    ],
    'message' => [
        'greeting' => 'Hello friend!',
        'rights' => 'Copyrights.',
        'salutation' => 'Thanks',
        'subject' => 'Message from courier',
        'notify' => 'If you’re having trouble clicking the button, copy and paste the URL below into your web browser.',
        'brand_name' => null,
    ],
    'challenge' => [
        'theme' => 'your-own-theme',
        'greeting' => 'Hello friend!',
        'email' => [
            'login' => [
                'before' => 'Recently, a login attempt was made on your account. You have X minutes to complete the login.',
                'after' => 'DO NOT share this code with anyone. If you did not request this login, you can ignore this email.',
            ],
            'password-reset' => [
                'before' => 'Recently, a login attempt was made on your account. You have X minutes to complete the login.',
                'after' => 'DO NOT share this code with anyone. If you did not request this password reset, you can ignore this email.',
            ],
        ],
    ],
    'panel' => [
        'label' => 'Courier',
        'icon' => 'email',
    ],
],

Warning

Since version 1.2.0, Courier changes the plugin prefix from beebmx.kirby-courier to beebmx.courier.

License

Licensed under the MIT.

Credits

Courier is inspired by the Laravel Notifications and Laravel Mail.