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.
Requirements ¶
The library requires PHP 5.2 or higher compiled with cURL extension.
How to install ¶
0. Install Composer:
~~~
curl -sS https://getcomposer.org/installer | php
~~~
0. Add php-mailgun dependency:
~~~
php composer.phar require baibaratsky/php-mailgun:*
~~~
How to use ¶
Just put php-mailgun in your extensions directory or use Composer, and add some code in the components section of your config file:
...
'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:
$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.
User Contributed Notes
Leave a comment
If you have any questions, please ask in the forum instead.
Join the conversation to share a note.