Automatically Provide an Online Version of Mailables

News

October 13th, 2020

new-mail-featured.png

Wagonwheel is a Laravel package by Sam Carré that provides an online version of your Laravel emails to users. It uses Laravel’s built-in signed URLs to create a URL for the online version, which is secured and makes it difficult to guess the URL.

It works by adding the SaveForOnlineViewing trait to any of your mailables. The readme provides the following example of a mailable:

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Sammyjo20\Wagonwheel\Concerns\SaveForOnlineViewing;

class BookingConfirmed extends Mailable
{
    use Queueable, SerializesModels, SaveForOnlineViewing;

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->subject('Booking Confirmed')
                    ->markdown('emails.bookings.confirmed');
    }
}

At the time of writing, you can customize the placement of the component in the email and the message expiry time that determines how long Wagonwheel should keep the online version. You can also publicize the package’s views if you need to customize the look and feel.

You can learn more about this package on GitHub.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.