2017 © Pedro PelĂĄez
 

library php-mailgun

Mailgun API PHP library and Yii extension (as well as Yii2)

image

baibaratsky/php-mailgun

Mailgun API PHP library and Yii extension (as well as Yii2)

  • Tuesday, September 8, 2015
  • by baibaratsky
  • Repository
  • 6 Watchers
  • 31 Stars
  • 7,392 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 14 Forks
  • 1 Open issues
  • 6 Versions
  • 3 % Grown

The README.md

Mailgun API PHP library

Packagist Packagist Packagist, (*1)

The library requires PHP 5.2 compiled with cURL extension., (*2)

How to install

  1. Install Composer:, (*3)

    curl -sS https://getcomposer.org/installer | php
    
  2. Add php-mailgun dependency:, (*4)

    php composer.phar require baibaratsky/php-mailgun:1.2.*
    

How to use

It’s pretty easy to send a message using this library:, (*5)

require_once(__DIR__ . '/vendor/autoload.php'); // Require autoload file generated by composer

$mailgun = new MailgunApi('example.com', 'key-somekey');

$message = $mailgun->newMessage();
$message->setFrom('me@example.com', 'Andrei Baibaratsky');
$message->addTo('you@yourdomain.com', 'My dear user');
$message->setSubject('Mailgun API library test');
$message->setText('Amazing! It’s working!');
$message->addTag('test'); // All the Mailgun-specific attributes, such as tags, vars, tracking, etc. are supported

$message->enableTestMode(); // Don’t forget to remove this string if you really want the message to be sent

// You can also use dry run to test your code without making real API requests (only for sendMessage())
// $mailgun->enableDryRun();

echo $message->send();

Batch sending is also supported. You can use recipient variables to customize messages., (*6)

The library fully supports listing, creating, updating, and deleting of mailing lists and their members:, (*7)

MailgunList[]        getMailingLists(int $limit = 100, int $skip = 0)
MailgunList          getMailingList(string $listAddress)
MailgunList          createMailingList(MailgunList $mailingList)
MailgunList          updateMailingList(string $listAddress, MailgunList $mailingList)
bool                 deleteMailingList(string $listAddress)
MailgunListMember[]  getMailingListMembers(string $listAddress, int $limit = 100, int $skip = 0)
MailgunListMember    getMailingListMember(string $listAddress, string $memberAddress)
MailgunListMember    addMemberToMailingList(string $listAddress, MailgunListMember $member, bool $upsert = false)
MailgunList          addMultipleMembersToMailingList(string $listAddress, array $members)
MailgunListMember    updateMailingListMember(string $listAddress, string $memberAddress, MailgunListMember $member)
bool                 deleteMailingListMember(string $listAddress, string $memberAddress)
array                getMailingListStats(string $listAddress)

Unsubscribes-related methods:, (*8)

MailgunUnsubscribe[] getUnsubscribes(int $limit = 100, int $skip = 0)
MailgunUnsubscribe[] getUserUnsubscribes(string $userAddress)
bool                 createUnsubscribe(MailgunUnsubscribe $unsubscribe)
bool                 deleteUnsubscribe(string $id)
bool                 deleteUserUnsubscribes(string $userAddress)

Spam Complaints:, (*9)

MailgunComplaint[]   getComplaints(int $limit = 100, int $skip = 0)
MailgunComplaint     getComplaint(string $userAddress)
bool                 createComplaint(MailgunComplaint $complaint)
bool                 deleteComplaint(string $userAddress)

Bounces:, (*10)

MailgunBounce[]      getBounces(int $limit = 100, int $skip = 0)
MailgunBounce        getBounce(string $userAddress)
bool                 createBounce(MailgunBounce $bounce)
bool                 deleteBounce(string $userAddress)

Routes:, (*11)

MailgunRoute[]       getRoutes(int $limit = 100, int $skip = 0)
MailgunRoute         getRoute(string $id)
MailgunRoute         createRoute(MailgunRoute $route)
MailgunRoute         updateRoute(string $id, MailgunRoute $route)
bool                 deleteRoute(string $id)

Webhook signature validation:, (*12)

if (!$mailgun->validateHook($_POST)) {
    echo 'Bad signature!';
}

Yii extension

Yii users can use this library as an extension. Just put php-mailgun in your extensions directory or use Composer, and add some code in the components section of your config file:, (*13)

...
    'components' => array(
        ...
        'mailgun' => array(
            'class' => 'vendor.baibaratsky.php-mailgun.MailgunYii',
            'domain' => 'example.com',
            'key' => 'key-somekey',
            'tags' => array('yii'), // You may also specify some Mailgun parameters
            'enableTracking' => false,
        ),
        ...
    ),
...

That’s all! Your application is ready to send messages. For example:, (*14)

$message = Yii::app()->mailgun->newMessage();
$message->setFrom('me@example.com', 'Andrei Baibaratsky');
$message->addTo('you@yourdomain.com', 'My dear user');
$message->setSubject('Mailgun API library test');

// You can use views to build your messages instead of setText() or setHtml():
$message->renderText('myView', array('myParam' => 'Awesome!'));

echo $message->send();

All the methods of the main library class are available in the Yii component., (*15)


Mailgun is a programmable email platform. It allows your application to become a fully-featured email server. Send and receive messages, create mailboxes and email campaigns with ease. You can find more information about Mailgun and its API here: http://documentation.mailgun.com, (*16)

The Versions

08/09 2015

dev-master

9999999-dev http://github.com/baibaratsky/php-mailgun

Mailgun API PHP library and Yii extension (as well as Yii2)

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.2
  • ext-curl *

 

The Development Requires

by Andrei Baibaratsky

mail email yii2 yii mailgun mailing lists

08/09 2015

v1.2.0

1.2.0.0 http://github.com/baibaratsky/php-mailgun

Mailgun API PHP library and Yii extension (as well as Yii2)

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.2
  • ext-curl *

 

The Development Requires

by Andrei Baibaratsky

mail email yii2 yii mailgun mailing lists

15/08 2015

v1.1.0

1.1.0.0 http://github.com/baibaratsky/php-mailgun

Mailgun API PHP library and Yii extension (as well as Yii2)

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.2
  • ext-curl *

 

The Development Requires

by Andrei Baibaratsky

mail email yii2 yii mailgun mailing lists

15/08 2015

v1.0.2

1.0.2.0 http://github.com/baibaratsky/php-mailgun

Mailgun API PHP library and Yii extension (as well as Yii2)

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.2
  • ext-curl *

 

The Development Requires

by Andrei Baibaratsky

mail email yii2 yii mailgun mailing lists

11/03 2015

v1.0.1

1.0.1.0 http://github.com/baibaratsky/php-mailgun

Mailgun API PHP library and Yii extension

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.2
  • ext-curl *

 

by Andrei Baibaratsky

mail email yii mailgun mailing lists

11/10 2014

v1.0

1.0.0.0 http://github.com/baibaratsky/php-mailgun

Mailgun API PHP library

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.2
  • ext-curl *

 

by Andrei Baibaratsky

mail email mailgun mailing lists