PHP code example of awsm3 / mailgun-zend3

1. Go to this page and download the library: Download awsm3/mailgun-zend3 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

awsm3 / mailgun-zend3 example snippets


/** @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('[email protected]', '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('[email protected]');
$recipient->setName('Recipient Name');
 
// Add the recipient to the message
$message->setTo($recipient->prepare());

// Or make recipients list
$recipientsList = new RecipientsList(
    new Recipient('[email protected]', 'Recipient 1'),
    new Recipient('[email protected]', 'Recipient 2'),
);
$message->setTo($recipientsList->prepare());
 
// Send the message
$response = $transport->messages()->send('your-domain', $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);