PHPackages                             soflomo/mail - 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. soflomo/mail

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

soflomo/mail
============

Module to to ease the use of sending e-mail messages in Zend Framework 2

5108.6k8[1 issues](https://github.com/juriansluiman/Soflomo-Mail/issues)PHP

Since Jul 18Pushed 8y ago4 watchersCompare

[ Source](https://github.com/juriansluiman/Soflomo-Mail)[ Packagist](https://packagist.org/packages/soflomo/mail)[ RSS](/packages/soflomo-mail/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Soflomo\\Mail
=============

[](#soflomomail)

[![Latest Stable Version](https://camo.githubusercontent.com/dbfe60dfd02258a307d5d089ce3a3d2742c387bc6e7671ee22c3db622f253be5/68747470733a2f2f706f7365722e707567782e6f72672f736f666c6f6d6f2f6d61696c2f762f737461626c652e706e67)](https://packagist.org/packages/soflomo/mail)[![Build Status](https://camo.githubusercontent.com/324a3e9d346ba92eac6c26d0252aa8df2aa870b5c819d69e941215145f8c42e9/68747470733a2f2f7472617669732d63692e6f72672f536f666c6f6d6f2f4d61696c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Soflomo/Mail)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2bebba2dedf1cfdf812dff3eb920bd9916fe93f54b0c3d6a2d9913ad4c038979/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f536f666c6f6d6f2f4d61696c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Soflomo/Mail/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/b85ca1191c2bca7b5d2e3964ff8ffd782e2eb0e99e1d24c40030ecbcb8ab2858/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f536f666c6f6d6f2f4d61696c2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Soflomo/Mail/?branch=master)[![Dependency Status](https://camo.githubusercontent.com/c0b75530c9e87e222a16d493800e24aabb890bc6cea6626022e63e920b5d950b/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3533633765353832306464343231306166303030303031622f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/53c7e5820dd4210af000001b)

Soflomo\\Mail is a facade module that integrates various components to send e-mails in Zend Framework 2. It allows users to compose messages, render templates and configure transports in one call. Every component is loosly coupled and can be replaced at runtime.

Soflomo\\Mail offers:

1. A single `send()` to configure a message, render the templates and send it
2. A default message objects with pre-filled variables like the "From" field
3. A default transport which can by configured inside your configuration files
4. All parts can be replaced by any of your own

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

[](#installation)

Soflomo\\Mail works with [Composer](https://getcomposer.org). Make sure you have the composer.phar downloaded and you have a `composer.json` file at the root of your project. To install it, add the following line into your `composer.json`file:

```
"require": {
    "soflomo/mail": "~0.3"
}

```

After installation of the package, you need to complete the following steps to use Soflomo\\Mail:

1. Enable the module by adding `Soflomo\Mail` to your `application.config.php`file.
2. Copy the `soflomo_mail.global.php.dist` (you can find this file in the `config` folder of Soflomo\\Mail) into your config/autoload folder and apply any setting you want.

Requirements
------------

[](#requirements)

1. Zend Framework 2: the `Zend\Mail` component
2. Zend Framework 2: the `Zend\ServiceManager` component

Usage
-----

[](#usage)

Soflomo\\Mail uses a central `MailService` facade. This service exposes a single `send()` method to send an email based on some variables:

```
// $serviceLocator is an instance of Zend\Service\ServiceManager

$service = $serviceLocator->get('Soflomo\Mail\Service\MailService');
$service->send(array(
  'to'       => 'bob@acme.com',
  'subject'  => 'Just want to say hi',
  'template' => 'email/test',
));
```

The three keys are required to send an email. In the above example, `template`is the name of the template which is resolved by the PhpRenderer and set as body in the message.

The `send()` configures the message, renders the `email/test` template and sends the message with a [configured transport](#smtp-sending-with-the-default-transport).

For controllers, a controller plugin exist to proxy to the email service:

```
public function sendAction()
{
    $this->email(array(
        'to'       => 'bob@acme.com',
        'subject'  => 'Just want to say hi',
        'template' => 'email/test',
    ));
}
```

### Additional options

[](#additional-options)

You can use, besides `to`, also `from`, `cc`, `bcc` and `reply_to`. For every addressee you can suffix the option with `_name` to set the name of the address part.

```
// $serviceLocator is an instance of Zend\Service\ServiceManager

$service = $serviceLocator->get('Soflomo\Mail\Service\MailService');
$service->send(array(
  'to'            => 'bob@acme.com',
  'subject'       => 'Just want to say hi',
  'template'      => 'email/test',

  'to_name'       => 'Bob',
  'from'          => 'alice@acme.com',
  'from_name'     => 'Alice',

  'cc'            => 'mike@acme.com',
  'cc_name'       => 'Mike',

  'bcc'           => 'john@acme.com'
  'bcc_name'      => 'John',

  'reply_to'      => 'internals@acme.com',
  'reply_to_name' => 'ACME Corp internals mailing list'
));
```

### Send to multiple recipients

[](#send-to-multiple-recipients)

You can make all of the addressees a key/value array. This allows you to send to multiple persons in one `send()` call.

```
// $serviceLocator is an instance of Zend\Service\ServiceManager

$service = $serviceLocator->get('Soflomo\Mail\Service\MailService');
$service->send(array(
  'to'       => array(
    'bob@acme.com' => 'Bob', 'alice@acme.com' => 'Alice'
  ),
  'subject'  => 'Just want to say hi',
  'template' => 'email/test',
));
```

At this moment, the array must be a key/value pair. Non-associative arrays are not recognized. If you want to leave the name blank, use `null`:

```
array('bob@acme.com' => null, 'alice@acme.com' => null)

```

### Send custom headers

[](#send-custom-headers)

You can add additional headers to the email message object with the `headers`key.

```
// $serviceLocator is an instance of Zend\Service\ServiceManager

$service = $serviceLocator->get('Soflomo\Mail\Service\MailService');
$service->send(array(
  'to'       => 'bob@acme.com',
  'subject'  => 'Just want to say hi',
  'template' => 'email/test',
  'headers'  => array(
    'X-Send-By' => 'MyCustomApp'
  ),
));
```

### Add attachments

[](#add-attachments)

Attachments is sent via the `attachments` key and should be an associative array where key is the filename to be used in the email and value is the absolute path to the attachment.

```
// $serviceLocator is an instance of Zend\Service\ServiceManager

$service = $serviceLocator->get('Soflomo\Mail\Service\MailService');
$service->send(array(
  'to'          => 'bob@acme.com',
  'subject'     => 'Just want to say hi',
  'template'    => 'email/test',
  'attachments' => array(
    'filename.ext' => '/absolute/path/to/file'
  ),
));
```

### Use template variables

[](#use-template-variables)

The `send()` method accepts a second paramter to inject variables in the view template.

```
// Your template
Welcome
```

```
// $serviceLocator is an instance of Zend\Service\ServiceManager

$service = $serviceLocator->get('Soflomo\Mail\Service\MailService');
$service->send(array(
  'to'       => 'bob@acme.com',
  'subject'  => 'Just want to say hi',
  'template' => 'email/test',
), array(
  'name'     => 'Bob',
));
```

### Use your own message object

[](#use-your-own-message-object)

If you happen to have a message object already, you can set it as the third parameter. You can have a message object which you have already configured partially or you need to reuse an instantiated message.

```
// $messaga is an instance of Zend\Mail\Message
// $serviceLocator is an instance of Zend\Service\ServiceManager

$message->setFrom('alice@acme.com');
$service = $serviceLocator->get('Soflomo\Mail\Service\MailService');
$service->send(array(
  'to'       => 'bob@acme.com',
  'subject'  => 'Just want to say hi',
  'template' => 'email/test',
), array(), $message);
```

### Layout

[](#layout)

In your config file you can set the path to a layoutfile and your email will be sent with that layout. To echo the content in the layout file you'll just use ``

You could also change the layout pr. email, by using the key `layout` in the options array.

Configuration
-------------

[](#configuration)

Soflomo\\Mail is completely configurable to your needs. The module utilizes dependency injection. This allows any user to drop in their own parts replacing the default services from Soflomo\\Mail. In the usage section, some examples are given for these situations.

### SMTP sending with the default transport

[](#smtp-sending-with-the-default-transport)

The transport Soflomo\\Mail uses (called `Soflomo\Mail\Transport`) is an alias for the default transport (`Soflomo\Mail\DefaultTransport`). You can use the default transport for configuration-based SMTP transports. Just copy this to your local config file in the `config/autoload` directory:

```
'soflomo_mail' => array(
    'transport' => array(
        'type'    => 'smtp',
        'options' => array(
            'name' => 'myserver.com',
            'host' => 'smtp.myserver.com',
            'connection_class'  => 'login',
            'connection_config' => array(
                'ssl'      => 'tls',
                'username' => 'my-username',
                'password' => 'my-password',
            ),
        ),
    ),
),
```

The 'type' can be a class from `Zend\Mail\Transport\*` (so either "file", "smtp" or "sendmail"). The `options` array is used to instantiate an options object corresponding to the type (for "smtp" an `SmtpOptions` class is used).

`soflomo_mail.global.php.dist` has more examples of different transport types and configurations.

Alternatively, give the type a FQCN and it utilizes that class for the transport. Be aware this FQCN is a simple solution and cannot implement dependency injection. For more advanced usage, see how to configure your [own custom transport](#use-your-custom-transport-factory).

### Use an existing alternative transport service

[](#use-an-existing-alternative-transport-service)

[SlmMail](http://github.com/juriansluiman/SlmMail) is a module which implements the API for various third party email providers like Mailgun, Postmark and Amazon SES.

All SlmMail transports are services in the service manager which you can use to inject in any other class. For Soflomo\\Mail, set the alias to the SlmMail transport you use and it's automatically injected.

```
'service_manager' => array(
    'aliases' => array(
        'Soflomo\Mail\Transport' => 'SlmMail\Mail\Transport\SendGridTransport',
    ),
),
```

### Use your custom transport factory

[](#use-your-custom-transport-factory)

When you have a custom transport and your factory registered, you can utilize it as well. Take the service name of your factory and set is as an alias.

```
'service_manager' => array(
    'factories' => array(
        'MyApp\Mail\Transport\MyTransport' => 'MyApp\Mail\Transport\MyTransportFactory'
    ),
    'aliases' => array(
        'Soflomo\Mail\Transport' => 'MyApp\Mail\Transport\MyTransport',
    ),
),
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b44d982b8aea8d0473108d45548edc68bab12702fb413edcb1598b3d81a69de?d=identicon)[Danielss89](/maintainers/Danielss89)

![](https://www.gravatar.com/avatar/5c8ca0c8435ae4c01c201bb52f63a72a8f9ef203f61535d7daf588f6b3a7df1c?d=identicon)[juriansluiman](/maintainers/juriansluiman)

---

Top Contributors

[![Danielss89](https://avatars.githubusercontent.com/u/632956?v=4)](https://github.com/Danielss89 "Danielss89 (18 commits)")[![basz](https://avatars.githubusercontent.com/u/143068?v=4)](https://github.com/basz "basz (13 commits)")

### Embed Badge

![Health badge](/badges/soflomo-mail/health.svg)

```
[![Health](https://phpackages.com/badges/soflomo-mail/health.svg)](https://phpackages.com/packages/soflomo-mail)
```

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M228](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M52](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

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