awsm3 / mailgun-zend3
A PHP client library for Mailgun's REST API for Zend Framework 3
0.1.0
2018-06-06 15:59 UTC
Requires
- php: >=7.0
- guzzlehttp/psr7: ^1.4
- mailgun/mailgun-php: ^2.5
- php-http/curl-client: ^1.7
- zendframework/zend-mail: ~2.7
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2025-03-22 02:10:56 UTC
README
A PHP ZF3 client library for Mailgun's API.
This library provides all of the functionality present in the official PHP client, but makes use of namespaces, provides helper classes to ease message sending and works with Zend Framework 3 (uses its library).
Installation Using Composer
Assuming composer.phar is located in your project's root directory, run the following command:
composer require awsm3/mailgun-zend3
Usage
Sending a Message
/** @uses */ use ZendMailgun\{ Mailgun, Struct\Message, Struct\Sender, Struct\Recipient, Struct\RecipientsList } // Instantiate a client object $transport = new Mailgun('your_api_key'); // Instantiate a sender $sender = new Sender('test@example.com', 'Your name'); // Instantiate a Message object $message = new Message(); // Define message properties $message->setText('Hello, username'); $message->setSubject('Test'); $message->setFrom($sender->prepare()); // Instantiate a Recipient object and add details $recipient = new Recipient(); $recipient->setEmail('recipient.email@example.com'); $recipient->setName('Recipient Name'); // Add the recipient to the message $message->setTo($recipient->prepare()); // Or make recipients list $recipientsList = new RecipientsList( new Recipient('recipient-1@mail.com', 'Recipient 1'), new Recipient('recipient-2@mail.com', 'Recipient 2'), ); $message->setTo($recipientsList->prepare()); // Send the message $response = $transport->messages()->send('your-domain', $message);
Sending a ZF3 Message
/** @uses */ use ZendMailgun\{ Mailgun, Struct\Message, Struct\Sender, Struct\Recipient, Struct\RecipientsList } // Convert from ZF message // $zfMessage is instance of \Zend\Mail\Message $message = Message::fromZendMessage($zfMessage); // Instantiate a client object $transport = new Mailgun('your_api_key'); // send the message $response = $transport->messages()->send('your-domain', $message);