spiral/sendit

Email builder and queue handler

v1.0.0 2020-04-29 11:26 UTC

This package is auto-updated.

Last update: 2020-07-02 18:48:39 UTC


README

Latest Stable Version Build Status Codecov

Email builder and queue handler.

Installation:

To install the component:

$ composer require spiral/sendit

Make sure to install required symfony/mailer drivers.

Activate the component bootloaders:

use Spiral\SendIt\Bootloader as Sendit;
// ...

protected const LOAD = [
    // ...
    Sendit\MailerBootloader::class,
    Sendit\BuilderBootloader::class,
    // ...
];

Configure the component using app/config/mailer.php file:

// Amazon SES
return [
    'dsn'  => sprintf(
        'ses+smtps://%s:%s@ses?region=%s',
        rawurlencode(env('AWS_KEY')),
        rawurlencode(env('AWS_SECRET')),
        env('AWS_REGION')
    ),
    'from' => 'Project Name <no-reply@project.com>',
];

Or specify ENV variables:

MAILER_DSN = "smtp://..."
MAILER_FROM = "Project Name <no-reply@project.com>"

Example:

The component provides the ability to compose content-rich email templates using Stempler views:

<extends:sendit:builder subject="I'm afraid I can't do that"/>
<use:bundle path="sendit:bundle"/>

<email:attach path="{{ $attachment }}" name="attachment.txt"/>

<block:html>
    <p>I'm sorry, {{ $name }}!</p>
    <p><email:image path="path/to/image.png"/></p>
</block:html>

To use:

use Spiral\Mailer;

function send(Mailer\MailerInterface $mailer)
{
    $mailer->send(new Mailer\Message(
        "template.dark.php", 
        "email@domain.com",
        [
            "name" => "Dave",
            "attachment" => __FILE__,
        ]
    ));
}

License:

MIT License (MIT). Please see LICENSE for more information. Maintained by Spiral Scout.