Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Mailgun plugin for CakePHP 3

Build Status Software License Latest Stable Version Total Downloads

This plugin provides email delivery using Mailgun. See this post for detailed examples.


This plugin has the following requirements:

  • CakePHP 3.0.0 or greater.
  • PHP 5.4.16 or greater.


You can install this plugin into your CakePHP application using composer.

composer require narendravaghela/cakephp-mailgun

After installation, Load the plugin


Or, you can load the plugin using the shell command

$ bin/cake plugin load MailgunEmail


Set your Mailgun credentials in EmailTransport settings in app.php

'EmailTransport' => [
  'mailgun' => [
      'className' => 'MailgunEmail.Mailgun',
      'apiKey' => 'key-123456789123456789', // your api key
      'domain' => '' // your sending domain

If you face an SSL certificate error, please follow below steps:

  1. Open
  2. Copy the entire page and save it as a "cacert.pem"
  3. Open your php.ini file and insert or update the following line: curl.cainfo = "[pathtofile]\cacert.pem"

And create new delivery profile for mailgun in Email settings.

'Email' => [
    'default' => [
        'transport' => 'default',
        'from' => 'you@localhost',
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    'mailgun' => [
        'transport' => 'mailgun'


You can now simply use the CakePHP Email to send an email via Mailgun.

$email = new Email('mailgun');
$result = $email->from(['' => 'Example Site'])
  ->subject('Welcome to CakePHP')
  ->viewVars(['foo' => 'Bar'])
  ->addHeaders(['o:tag' => 'testing'])
  ->addHeaders(['o:deliverytime' => strtotime('+1 Min')])
  ->addHeaders(['v:my-custom-data' => json_encode(['foo' => 'bar'])])
      'cake_icon1.png' => Configure::read('App.imageBaseUrl') . 'cake.icon.png',
      'cake_icon2.png' => ['file' => Configure::read('App.imageBaseUrl') . 'cake.icon.png'],
      WWW_ROOT . 'favicon.ico'
  ->send('Your email content here');

That is it.

Reporting Issues

If you have a problem with this plugin or any bug, please open an issue on GitHub.