PHPackages                             lekoala/silverstripe-mailgun - 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. lekoala/silverstripe-mailgun

ActiveSilverstripe-vendormodule

lekoala/silverstripe-mailgun
============================

Mailgun integration for SilverStripe CMS

1.2.2(2y ago)312.0k11[1 issues](https://github.com/lekoala/silverstripe-mailgun/issues)MITPHPPHP &gt;=8CI failing

Since Jan 29Pushed 1y ago2 watchersCompare

[ Source](https://github.com/lekoala/silverstripe-mailgun)[ Packagist](https://packagist.org/packages/lekoala/silverstripe-mailgun)[ RSS](/packages/lekoala-silverstripe-mailgun/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (8)Versions (10)Used By (0)

SilverStripe Mailgun module
===========================

[](#silverstripe-mailgun-module)

[![Build Status](https://camo.githubusercontent.com/aab3fc191e15fe0146b1f738ef7b19eb87264c33cc3ed8e2e7ac9a32cc5bdb13/68747470733a2f2f7472617669732d63692e6f72672f6c656b6f616c612f73696c7665727374726970652d6d61696c67756e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/lekoala/silverstripe-mailgun)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4572a5b277fa9ab8a1ddbb3d97017d2d2f7731e819c7b136811d41e230e74394/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c656b6f616c612f73696c7665727374726970652d6d61696c67756e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/lekoala/silverstripe-mailgun/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/249d692e756f7e0db62f30d87a46dc6c4d162cb8e3eb4aa145910c9301de75f1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c656b6f616c612f73696c7665727374726970652d6d61696c67756e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/lekoala/silverstripe-mailgun/?branch=master)[![Build Status](https://camo.githubusercontent.com/66cbdefc34f94325f605ec7df8c5c6d089563f94b674202db283ad4ebc03eb1c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c656b6f616c612f73696c7665727374726970652d6d61696c67756e2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/lekoala/silverstripe-mailgun/build-status/master)[![codecov.io](https://camo.githubusercontent.com/d0b1113e57f9a724073ce0d6a51b645a174bd0b83da4ee6f4d0f87995c0304e3/68747470733a2f2f636f6465636f762e696f2f6769746875622f6c656b6f616c612f73696c7665727374726970652d6d61696c67756e2f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/github/lekoala/silverstripe-mailgun?branch=master)

[![Latest Stable Version](https://camo.githubusercontent.com/d20093c4fe60950059d3c9b8997c78a5268d140577ea5650ece4ff64eded9763/68747470733a2f2f706f7365722e707567782e6f72672f6c656b6f616c612f73696c7665727374726970652d6d61696c67756e2f76657273696f6e)](https://packagist.org/packages/lekoala/silverstripe-mailgun)[![Latest Unstable Version](https://camo.githubusercontent.com/55f8d147ebda3aa9e7c96bfe1d7c16bc0bba70a547a1576dddb1fce47622581c/68747470733a2f2f706f7365722e707567782e6f72672f6c656b6f616c612f73696c7665727374726970652d6d61696c67756e2f762f756e737461626c65)](//packagist.org/packages/lekoala/silverstripe-mailgun)[![Total Downloads](https://camo.githubusercontent.com/0234616d78f38fa3f575d3e0e86c1d476693f39a99fb955919076d079c333cca/68747470733a2f2f706f7365722e707567782e6f72672f6c656b6f616c612f73696c7665727374726970652d6d61696c67756e2f646f776e6c6f616473)](https://packagist.org/packages/lekoala/silverstripe-mailgun)[![License](https://camo.githubusercontent.com/4b4771b1bf1e22713dbf33c7c15cd79f66e12dab44b56716662a319d23fecdc0/68747470733a2f2f706f7365722e707567782e6f72672f6c656b6f616c612f73696c7665727374726970652d6d61696c67756e2f6c6963656e7365)](https://packagist.org/packages/lekoala/silverstripe-mailgun)[![Monthly Downloads](https://camo.githubusercontent.com/e4ea33cfc13c0c9c1fa7b3206d91f8e3642269403dccc9f7ae795852ed383e40/68747470733a2f2f706f7365722e707567782e6f72672f6c656b6f616c612f73696c7665727374726970652d6d61696c67756e2f642f6d6f6e74686c79)](https://packagist.org/packages/lekoala/silverstripe-mailgun)[![Daily Downloads](https://camo.githubusercontent.com/f7c0d6e7551d6cf868ff1683a8f56243867ea63bc4c70a7759b4f5cb618b2a18/68747470733a2f2f706f7365722e707567782e6f72672f6c656b6f616c612f73696c7665727374726970652d6d61696c67756e2f642f6461696c79)](https://packagist.org/packages/lekoala/silverstripe-mailgun)

[![codecov.io](https://camo.githubusercontent.com/f9ddc0aba620bfeff39daa71bb0323afd903a835d2857b2aab0ae26c149d6c34/68747470733a2f2f636f6465636f762e696f2f6769746875622f6c656b6f616c612f73696c7665727374726970652d6d61696c67756e2f6272616e63682e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/f9ddc0aba620bfeff39daa71bb0323afd903a835d2857b2aab0ae26c149d6c34/68747470733a2f2f636f6465636f762e696f2f6769746875622f6c656b6f616c612f73696c7665727374726970652d6d61696c67756e2f6272616e63682e7376673f6272616e63683d6d6173746572)

Setup
-----

[](#setup)

Define in your .env file the following variables

```
MAILGUN_API_KEY='YOUR_API_KEY_HERE'
MAILGUN_DOMAIN='example.com'

```

or by defining the api key in your config.yml

```
LeKoala\Mailgun\MailgunHelper:
    api_key: 'YOUR_API_KEY_HERE'
    domain: 'example.com'
```

This module uses the [official client](https://github.com/mailgun/mailgun-php)Also make sure to check the [official documentation](https://documentation.mailgun.com/en/latest/index.html)

You can also autoconfigure the module with the following environment variables

```
# Will log emails in the temp folders
MAILGUN_ENABLE_LOGGING=true
# Will disable sending (useful in development)
MAILGUN_SENDING_DISABLED=true

```

By defining the Api Key, the module will register a new transport that will be used to send all emails.

If you're using the [Mailgun EU service](https://documentation.mailgun.com/en/latest/api-intro.html#base-url) you can change the API endpoint

```
# Will use https://api.eu.mailgun.net/v3
MAILGUN_ENDPOINT='https://api.eu.mailgun.net/v3'

```

Debug
-----

[](#debug)

Create a postbin  and set the following parameters

```
MAILGUN_ENDPOINT='http://bin.mailgun.net/XXX'
MAILGUN_DEBUG=true

```

Please note that the test suite does not work with postbin because it returns html response and do not mock api behaviour

Register the new mailer
-----------------------

[](#register-the-new-mailer)

If you define the MAILGUN\_API\_KEY variable, the mailer transport will be automatically registered.

Otherwise, you need to call the following line:

```
MailgunHelper::registerTransport();
```

Mailgun integration
-------------------

[](#mailgun-integration)

This module create a new admin section that allows you to:

- List all messages events and allow searching them
- Have a settings tab to list and configure sending domains and webhook

NOTE : Make sure that you have a valid api key (not a subaccount key) to access features related to installation of the webhook through the CMS.

Setting tags or metadata
------------------------

[](#setting-tags-or-metadata)

By using custom headers you can pass parameters to the api by following the same principle than the SMTP api.

The main way to pass parameters is to add a json encoded string through the X-Mailgun-Variables header, but you can also use that Mandrill compatiblity layer.

```
$email = new Email();
$email->setSubject($subject);
$email->setBody($body);
// Through Mandrill compat layer
$email->getSwiftMessage()->getHeaders()->addTextHeader('X-MC-Metadata', json_encode(['FIRST_NAME' => 'Jon Smith']));
// Or use Mailgun
$email->getSwiftMessage()->getHeaders()->addTextHeader('X-Mailgun-Variables', json_encode(['FIRST_NAME' => 'Jon Smith']));
```

Webhooks
--------

[](#webhooks)

NOT IMPLEMENTED YET

From the Mailgun Admin, you can setup a webhook for your website. This webhook will be called and MailgunController will take care of handling all events for you. It is registered under the \_\_mailgun/ route.

By default, MailgunController will do nothing. Feel free to add your own extensions to MailgunController to define your own rules, like "Send an email to the admin when a receive a spam complaint".

MailgunController provides the following extension point for all events:

- onAnyEvent

And the following extensions points depending on the type of the event:

- onEngagementEvent
- onGenerationEvent
- onMessageEvent
- onUnsubscribeEvent

You can also inspect the whole payload and the batch id with

- beforeProcessPayload : to check if a payload has been processed
- afterProcessPayload : to mark the payload has been processed or log information

You can test if your extension is working properly by visiting /\_\_mailgun/test if your site is in dev mode. It will load sample data from the API.

Please ensure that the url for the webhook is properly configured if required by using the following configuration

```
LeKoala\Mailgun\MailgunAdmin:
    webhook_base_url: 'https://my.domain.com/'
```

You can also define the following environment variable to log all incoming payload into a given directory. Make sure the directory exists. It is relative to your base folder.

```
MAILGUN_WEBHOOK_LOG_DIR='_incoming'

```

Preventing spam
---------------

[](#preventing-spam)

- Make sure you have properly configured your [SPF](https://mxtoolbox.com/SPFRecordGenerator.aspx) and DKIM records for your domain.

    mydomain.com TXT "v=spf1 include:mailgun.org ~all"
- Create a [DMARC record](https://www.unlocktheinbox.com/dmarcwizard/)

    \_dmarc.mydomain.com. 3600 IN TXT "v=DMARC1; p=none; sp=none; rf=afrf; pct=100; ri=86400"
- Leave provide\_plain option to true or provide plain content for your emails
- Use [Mail Tester](http://www.mail-tester.com/) to troubleshoot your issues

Inlining styles
---------------

[](#inlining-styles)

In order to have the best resulst, we use the package pelago\\emogrifier to inline styles

If you want to restore default functionnality, use this

```
LeKoala\Mailgun\MailgunHelper:
    inline_styles: false
```

Todo
----

[](#todo)

- Support multiple domains

Compatibility
-------------

[](#compatibility)

Tested with 4.4 but should work fine on any 4.x

Maintainer
----------

[](#maintainer)

LeKoala -

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance22

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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 ~155 days

Total

8

Last Release

847d ago

PHP version history (2 changes)1.0.0PHP &gt;=7

1.2.0PHP &gt;=8

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/250762?v=4)[Thomas Portelange](/maintainers/lekoala)[@lekoala](https://github.com/lekoala)

---

Top Contributors

[![lekoala](https://avatars.githubusercontent.com/u/250762?v=4)](https://github.com/lekoala "lekoala (36 commits)")[![gurucomkz](https://avatars.githubusercontent.com/u/12028675?v=4)](https://github.com/gurucomkz "gurucomkz (3 commits)")[![Linkdup](https://avatars.githubusercontent.com/u/1018387?v=4)](https://github.com/Linkdup "Linkdup (3 commits)")[![td204](https://avatars.githubusercontent.com/u/302822?v=4)](https://github.com/td204 "td204 (2 commits)")[![iqmeckert](https://avatars.githubusercontent.com/u/8713560?v=4)](https://github.com/iqmeckert "iqmeckert (1 commits)")

---

Tags

mailgunsilverstripesilverstripecmsmodulemailgun

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/lekoala-silverstripe-mailgun/health.svg)

```
[![Health](https://phpackages.com/badges/lekoala-silverstripe-mailgun/health.svg)](https://phpackages.com/packages/lekoala-silverstripe-mailgun)
```

###  Alternatives

[lekoala/silverstripe-mandrill

Adds mandrill in the SilverStripe CMS

1827.3k](/packages/lekoala-silverstripe-mandrill)[axyr/silverstripe-adminlogin

Use a custom login screen to log in to the admin section

165.8k](/packages/axyr-silverstripe-adminlogin)

PHPackages © 2026

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