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

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

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

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

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

Since May 23Pushed 1y 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 1mo ago

READMEChangelog (10)Dependencies (4)Versions (14)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.

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.Support
-------

[](#support)

If you are having general issues with this library, then please feel free to contact me on [Twitter](https://twitter.com/andyer92).

If you believe you have found an issue, please report it using the [issue tracker](https://github.com/andrewdyer/slim3-mailer/issues), or better yet, fork the repository and submit a pull request.

If you're using this package, I'd love to hear your thoughts!

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

42

—

FairBetter than 90% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 85.5% 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

513d 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 (53 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)")[![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

812.0k1](/packages/yuan1994-tp-mailer)[cattong/think-mailer

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

361.9k1](/packages/cattong-think-mailer)

PHPackages © 2026

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