PHPackages                             semhoun/slim-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. semhoun/slim-mailer

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

semhoun/slim-mailer
===================

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

1.0.0(6y ago)23.1k↓100%1MITPHPPHP &gt;=7.1

Since Oct 3Pushed 6y ago2 watchersCompare

[ Source](https://github.com/semhoun/slim-mailer)[ Packagist](https://packagist.org/packages/semhoun/slim-mailer)[ Docs](https://github.com/semhoun/slim-mailer)[ RSS](/packages/semhoun-slim-mailer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

Slim 4 Mailer
=============

[](#slim-4-mailer)

[![Latest Stable Version](https://camo.githubusercontent.com/8f5fc59164d28880f8907566ff7e8dd1f2fe242b104681e203589652f285af82/68747470733a2f2f706f7365722e707567782e6f72672f73656d686f756e2f736c696d2d6d61696c65722f762f737461626c65)](https://packagist.org/packages/semhoun/slim-mailer) [![Total Downloads](https://camo.githubusercontent.com/e7df7f79e135062c162e3fe6e1266a8a6de928238d669fed87aa59369976ac50/68747470733a2f2f706f7365722e707567782e6f72672f73656d686f756e2f736c696d2d6d61696c65722f646f776e6c6f616473)](https://packagist.org/packages/semhoun/slim-mailer) [![Latest Unstable Version](https://camo.githubusercontent.com/d06922e2404315f3b9026a817c95478e758bfd828d0de73162bc03f45aec255d/68747470733a2f2f706f7365722e707567782e6f72672f73656d686f756e2f736c696d2d6d61696c65722f762f756e737461626c65)](https://packagist.org/packages/semhoun/slim-mailer) [![License](https://camo.githubusercontent.com/ef7c866feb020da62e2a2ada697a20b0f9521427c61fe9f6010e012e005fb6e8/68747470733a2f2f706f7365722e707567782e6f72672f73656d686f756e2f736c696d2d6d61696c65722f6c6963656e7365)](https://packagist.org/packages/semhoun/slim-mailer) [![Monthly Downloads](https://camo.githubusercontent.com/b3b8326d72fafc91ec4ea7f5bee17badd0ed4c8886cce43c5d166aed450eeaa6/68747470733a2f2f706f7365722e707567782e6f72672f73656d686f756e2f736c696d2d6d61696c65722f642f6d6f6e74686c79)](https://packagist.org/packages/semhoun/slim-mailer)

Email support for the Slim 4 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.

Derivated from

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

[](#installation)

```
composer require semhoun/slim-mailer
```

Usage
-----

[](#usage)

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

```
$containerBuilder = new ContainerBuilder();
$containerBuilder->addDefinitions([
	'mailer' => function (ContainerInterface $container) {
            $settings = $container->get('settings');
            $view = $container->get('view');
			$mailer = new \Semhoun\Mailer\Mailer($view, [
                '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();
```

### 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('/email', function (Request $request, Response $response, $args)  use($app) {
	$user = new stdClass;
    $user->name = 'Paul Muaddib';
    $user->email = 'paul.muaddib@mail.com';

    $container = $app->getContainer();
    $container->get('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 Semhoun\\Mailer\\Mailable` class;

```
use Semhoun\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('/email', function (Request $request, Response $response, $args)  use($app) {
	$user = new stdClass;
    $user->name = 'Paul Muaddib';
    $user->email = 'paul.muaddib@mail.com';

    $container = $app->getContainer();
    $container->get('mailer')->->setTo($user->email, $user->name)->sendMessage(new WelcomeMailable($user));

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

    return $response;
});
```

### Methods

[](#methods)

MethodDescription`attachDynamic(string $data, string $filename, string $mime)`Attach in memory data.`attachFile(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 message`setDate(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.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

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

2409d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/efb83f2b876f8b6122c07c99af97df13bf208ba264d77b7b08dc1a1e30365e20?d=identicon)[semhoun](/maintainers/semhoun)

---

Tags

emailslimmaileremailsswiftmailerslim4slim-frameworkslim-mailslim-mailer

### Embed Badge

![Health badge](/badges/semhoun-slim-mailer/health.svg)

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

###  Alternatives

[andrewdyer/slim3-mailer

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

1032.7k](/packages/andrewdyer-slim3-mailer)[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)
