PHPackages                             andrewdyer/slim3-mailer - 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. andrewdyer/slim3-mailer

Abandoned → [https://github.com/andrewdyer/mailer](/?search=https%3A%2F%2Fgithub.com%2Fandrewdyer%2Fmailer)ArchivedLibrary[Mail &amp; Notifications](/categories/mail)

andrewdyer/slim3-mailer
=======================

Email support for the Slim Framework using Twig and Swift Mailer.

1.2.3(1y ago)1034.0k↓52%3[1 issues](https://github.com/andrewdyer/slim3-mailer/issues)MITPHPPHP &gt;=7.1CI failing

Since May 23Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/andrewdyer/slim3-mailer)[ Packagist](https://packagist.org/packages/andrewdyer/slim3-mailer)[ Docs](https://github.com/andrewdyer/slim3-mailer)[ RSS](/packages/andrewdyer-slim3-mailer/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (4)Versions (16)Used By (0)

Slim3 Mailer
============

[](#slim3-mailer)

 [![Total Downloads](https://camo.githubusercontent.com/4d66d4bbe0ca0c25f36dc7721fe3845120a50738218bae467250115639471c09/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f736c696d332d6d61696c65722f646f776e6c6f6164733f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/andrewdyer/slim3-mailer) [![Latest Stable Version](https://camo.githubusercontent.com/f9d31c6f95836115093b8ca8376326a84901a064025ab3ada26a9e5b41424aa3/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f736c696d332d6d61696c65722f763f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/andrewdyer/slim3-mailer) [![License](https://camo.githubusercontent.com/a0ac53d8169cadcdbc20e24ed4de7d47c705353fd202a7c3b2d58a71f780f168/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f736c696d332d6d61696c65722f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/andrewdyer/slim3-mailer)

Email support for the Slim Framework using Twig and [Swift Mailer](https://github.com/swiftmailer/swiftmailer). Mailable classes will massively tidy up your controller methods or routes, and will make sending email a breeze.

⚠️ This package has been archived
---------------------------------

[](#️-this-package-has-been-archived)

`andrewdyer/slim3-mailer` is no longer maintained. A modern replacement is available at [`andrewdyer/mailer`](https://github.com/andrewdyer/mailer), which is framework-agnostic, supports PHP 8.3, and replaces SwiftMailer with Symfony Mailer.

See the [migration guide](#migrating-to-andrewdyermailer) below for upgrade instructions.

License
-------

[](#license)

Licensed under MIT. Totally free for private or commercial projects.

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

[](#installation)

```
composer require andrewdyer/slim3-mailer
```

Usage
-----

[](#usage)

Attach a new instance of `Anddye\Mailer\Mailer` to your applications container so it can be accessed anywhere you need. `Mailer` takes two arguements; an instance of `Slim\Views\Twig` and an optional array of SMTP settings.

```
$app = new Slim\App;

$container = $app->getContainer();

$container['mailer'] = function($container) {
    $twig = $container['view'];
    $mailer = new Anddye\Mailer\Mailer($twig, [
        'host'      => '',  // SMTP Host
        'port'      => '',  // SMTP Port
        'username'  => '',  // SMTP Username
        'password'  => '',  // SMTP Password
        'protocol'  => ''   // SSL or TLS
    ]);

    // Set the details of the default sender
    $mailer->setDefaultFrom('no-reply@mail.com', 'Webmaster');

    return $mailer;
};

$app->run();
```

If your application doesn't use Twig views already, you will need to also attach this to your container.

```
$container['view'] = function ($container) {
    $view = new Slim\Views\Twig(__DIR__ . '/../resources/views');
    $basePath = rtrim(str_ireplace('index.php', '', $container['request']->getUri()->getBasePath()), '/');
    $view->addExtension(new Slim\Views\TwigExtension($container['router'], $basePath));

    return $view;
};
```

### Supported Options

[](#supported-options)

OptionTypeDescriptionhoststringThe host to connect to.portintegerThe port to connect to.usernamestringThe username to authenticate with.passwordstringThe password to authenticate with.protocolstringThe encryption method, either SSL or TLS.### Sending the Email (Basic Example)

[](#sending-the-email-basic-example)

```
$app->get('/', function ($request, $response) use($container) {
    $user = new stdClass;
    $user->name = 'John Doe';
    $user->email = 'johndoe@mail.com';

    $container['mailer']->sendMessage('emails/welcome.html.twig', ['user' => $user], function($message) use($user) {
        $message->setTo($user->email, $user->name);
        $message->setSubject('Welcome to the Team!');
    });

    $response->getBody()->write('Mail sent!');

    return $response;
});
```

**welcome.html.twig**

```
Hello {{ user.name }}

Welcome to the Team!

Love, Admin
```

### Sending with a Mailable

[](#sending-with-a-mailable)

Using mailable classes are a lot more elegant than the basic usage example above. Building up the mail in a mailable class cleans up controllers and routes, making things look a more tidy and less cluttered as well as making things so much more manageable.

Mailable classes are required to extend the base `Anddye\Mailer\Mailable` class;

```
use Anddye\Mailer\Mailable;

class WelcomeMailable extends Mailable
{

    protected $user;

    public function __construct($user)
    {
        $this->user = $user;
    }

    public function build()
    {
        $this->setSubject('Welcome to the Team!');
        $this->setView('emails/welcome.html.twig', [
            'user' => $this->user
        ]);

        return $this;
    }

}
```

Now in your controller or route, you set the recipients address and name, passing just a single argument into the `sendMessage` method - a new instance of the mailable class;

```
$app->get('/', function ($request, $response) use($container) {
    $user = new stdClass;
    $user->name = 'John Doe';
    $user->email = 'johndoe@mail.com';

    $container['mailer']->setTo($user->email, $user->name)->sendMessage(new WelcomeMailable($user));

    $response->getBody()->write('Mail sent!');

    return $response;
});
```

### Methods

[](#methods)

MethodDescriptionattachFile(string $path)Path to a file to set as an attachment.detachFile(string $path)Path to a file to remove as an attachment.setBcc(string $address, string $name = '')Set the Bcc of the message.setBody($body)Set the body of the message.setCc(string $address, string $name = '')Set the Cc of the messagesetDate(DateTimeInterface $dateTime)Set the date at which this message was created.setFrom(string $address, string $name = '')Set the sender of the message.setReplyTo(string $address, string $name = '')Set the ReplyTo of the message.setPriority(int $priority)Set the priority of the message.setSubject(string $subject)Set the subject of the message.setTo(string $address, string $name = '')Set the recipent of the message.Migrating to andrewdyer/mailer
------------------------------

[](#migrating-to-andrewdyermailer)

[`andrewdyer/mailer`](https://github.com/andrewdyer/mailer) is the modern replacement for this package. The core concept of mailable classes is retained, but the API has been updated to reflect current PHP and dependency standards.

### What has changed

[](#what-has-changed)

slim3-mailermailerDepends on `slim/slim` and `slimphp/twig-view`Framework-agnostic, accepts any `Twig\Environment`Uses `swiftmailer/swiftmailer` (abandoned)Uses `symfony/mailer` via a swappable transport interface`Mailable::build()` configures the message`Mailable::envelope()` and `Mailable::content()` separate routing from contentSMTP settings passed as an arrayTransport injected via DSN string`$mailer->setTo()->sendMessage(new WelcomeMailable())``$mailer->send(new WelcomeMail())`### Installation

[](#installation-1)

Remove the old package and install the new one:

```
composer remove andrewdyer/slim3-mailer
composer require andrewdyer/mailer
```

### Updating a mailable class

[](#updating-a-mailable-class)

**Before:**

```
use Anddye\Mailer\Mailable;

class WelcomeMailable extends Mailable
{
    public function __construct(private $user) {}

    public function build()
    {
        $this->setSubject('Welcome to the Team!');
        $this->setView('emails/welcome.html.twig', [
            'user' => $this->user,
        ]);

        return $this;
    }
}
```

**After:**

```
use AndrewDyer\Mailer\Mailable;
use AndrewDyer\Mailer\Values\Address;
use AndrewDyer\Mailer\Values\Content;
use AndrewDyer\Mailer\Values\Envelope;

class WelcomeMail extends Mailable
{
    public function __construct(private readonly User $user) {}

    public function envelope(): Envelope
    {
        return new Envelope(
            to:      new Address($this->user->email, $this->user->name),
            subject: 'Welcome to the Team!',
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails/welcome.html.twig',
            data: ['user' => $this->user],
        );
    }
}
```

### Updating the mailer setup in Slim 3

[](#updating-the-mailer-setup-in-slim-3)

**Before:**

```
$container['mailer'] = function ($container) {
    $mailer = new Anddye\Mailer\Mailer($container['view'], [
        'host'     => '',
        'port'     => '',
        'username' => '',
        'password' => '',
        'protocol' => '',
    ]);

    $mailer->setDefaultFrom('no-reply@mail.com', 'Webmaster');

    return $mailer;
};
```

**After:**

```
use AndrewDyer\Mailer\Mailer;
use AndrewDyer\Mailer\Drivers\SymfonyTransport;
use AndrewDyer\Mailer\Values\Address;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;

$container['mailer'] = function ($container) {
    $mailer = new Mailer(
        twig:        $container['view']->getTwig(),
        transport:   new SymfonyTransport('smtp://username:password@host:port'),
        defaultFrom: new Address('no-reply@mail.com', 'Webmaster'),
    );

    return $mailer;
};
```

Note that `getTwig()` unwraps the underlying `Twig\Environment` from `slim/twig-view`, which is all `andrewdyer/mailer` requires.

### Sending a mailable

[](#sending-a-mailable)

**Before:**

```
$container['mailer']->setTo($user->email, $user->name)->sendMessage(new WelcomeMailable($user));
```

**After:**

```
$container['mailer']->send(new WelcomeMail($user));
```

The `to` address is now defined inside the mailable's `envelope()` rather than being set on the mailer at call time.

Useful Links
------------

[](#useful-links)

- [Slim Framework](https://www.slimframework.com)
- [Slim Framework Twig View](https://github.com/slimphp/Twig-View)
- [Swift Mailer](https://github.com/swiftmailer/swiftmailer)

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance67

Regular maintenance activity

Popularity35

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 83.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~200 days

Recently: every ~350 days

Total

13

Last Release

560d ago

PHP version history (3 changes)v1.0.0PHP &gt;=7.1.14

1.1.2PHP &gt;=7.0.0

1.2.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/666597ea6e46748a89fe8764d1a45b4d0da97daf1bb1e9770ea34ae41f706d08?d=identicon)[andrewdyer](/maintainers/andrewdyer)

---

Top Contributors

[![andrewdyer](https://avatars.githubusercontent.com/u/8114523?v=4)](https://github.com/andrewdyer "andrewdyer (54 commits)")[![controlnocontrol](https://avatars.githubusercontent.com/u/10274536?v=4)](https://github.com/controlnocontrol "controlnocontrol (3 commits)")[![2ik](https://avatars.githubusercontent.com/u/6692517?v=4)](https://github.com/2ik "2ik (2 commits)")[![adamgeorgsson](https://avatars.githubusercontent.com/u/2567087?v=4)](https://github.com/adamgeorgsson "adamgeorgsson (2 commits)")[![Ejdamm](https://avatars.githubusercontent.com/u/2567087?v=4)](https://github.com/Ejdamm "Ejdamm (2 commits)")[![xemose](https://avatars.githubusercontent.com/u/40429716?v=4)](https://github.com/xemose "xemose (2 commits)")

---

Tags

emailemailsmailerphpslimslim-frameworkslim-mailslim-mailerslim3swiftmaileremailslimmaileremailsswiftmailerslim-frameworkslim3slim-mailslim-mailer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/andrewdyer-slim3-mailer/health.svg)

```
[![Health](https://phpackages.com/badges/andrewdyer-slim3-mailer/health.svg)](https://phpackages.com/packages/andrewdyer-slim3-mailer)
```

###  Alternatives

[yuan1994/tp-mailer

A powerful and beautiful php mailer for All of ThinkPHP and Other PHP Frameworks based SwiftMailer

892.0k1](/packages/yuan1994-tp-mailer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
