PHP code example of ride / lib-mail-mandrill

1. Go to this page and download the library: Download ride/lib-mail-mandrill 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/ */

    

ride / lib-mail-mandrill example snippets




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('[email protected]');
    $message->addCc('To 2 <[email protected]>');
    $message->addBcc(array('[email protected]', 'To 3 <[email protected]>'));
    $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) {
        
    }
}