ride/lib-mail-mandrill

Mandrill implementation for the mail library of the Ride framework

1.1.0 2019-12-10 16:27 UTC

This package is auto-updated.

Last update: 2024-03-11 01:44:29 UTC


README

Mandrill implementation for the mail library of the PHP Ride framework.

For more information, you can check the Mandrill website.

What's In This Library

MandrillTransport

The MandrillTransport class implements the Transport interface. It uses the Mandrill rest API to send mails. You can set tags and the subaccount for all mails sent by the transport.

MandrillMailMessage

The MandrillMessage class extends the MailMessage class. You can set tags and the subaccount for a mail message individually.

Code Sample

<?php

use ride\library\log\Log;
use ride\library\mail\transport\MandrillTransport;

function createTransport($apiKey, Log $log) {
    $transport = new MandrillTransport($apiKey, $log);
    
    // a tag and subaccount to be set on all mails which don't set tags or a subaccount
    $transport->addTag('newsletter');
    $transport->setSubAccount('my-subaccount');
    
    return $transport;
}

function sendMail(MandrillTransport $transport) {
    // like any mail message
    $message = $transport->createMessage();
    $message->setSubject('My subject');
    $message->setRecipient('to@domain.com');
    $message->addCc('To 2 <to2@domain.com>');
    $message->addBcc(array('to3@domain.com', 'To 3 <to3@domain.com>'));
    $message->setIsHtmlMessage(true);
    $message->setMessage('<html><body><p>...</p></body></html>');
    
    // mandrill extension, override the transport tags and subaccount
    $message->addTag('registration');
    $message->setSubAccount('my-other-subaccount');
    
    // send it
    try {
        $transport->send($message);
    } catch (MailException $exception) {
        
    }
}

Related Modules

Installation

You can use Composer to install this library.

composer require ride/lib-mail-mandrill