ride/lib-mail

Mail library of the Ride framework

1.0.0 2016-10-13 12:10 UTC

This package is auto-updated.

Last update: 2024-04-12 23:07:34 UTC


README

Mail library of the PHP Ride framework.

What's In This Library

MailAddress

The MailAddress class is used to deal with email addresses. All recipients of a MailMessage are set with this class. It allows straight email addresses but also addresses in the format of name .

MailMessage

The MailMessage class is a data container of the mail to send. You can set the recipients through the To, CC and BCC field. You can flag a message as an HTML message, add attachments and more.

MimePart

The MimePart class is internally used to add attachments to a MailMessage. You can use it manually to create a custom multipart message.

Transport

The Transport interface offers a way to implement the actual sending of a mail. It's also the starting point when you want to send a mail with this library as it also acts as a factory for messages.

A generic implentation is provided is this library through the SimpleTransport class. This uses the PHP functions to send a mail.

MessageParser

The MessageParser class is a helper for the Transport implementations. It takes a MailMessage and extracts all information into a structure which can be used by the transport.

Code Sample

Check the following code sample to some of the possibilities of this library.

<?php

use ride\library\log\Log;
use ride\library\mail\transport\SimpleTransport;
use ride\library\mail\transport\Transport;
use ride\library\system\file\FileSystem;

function createTransport(Log $log) {
    // simple, create an instance
    $transport = new SimpleTransport($log);
    
    // you set some defaults to you don't have to set this to each message
    $transport->setDefaultFrom('from@domain.com');
    $transport->setDefaultReplyTo('from@domain.com');
    
    // you can set a debug address 
    // no recipients in the To, CC and BCC will receive the message, only this debug to address
    $transport->setDebugTo('me@domain.com');
    
    return $transport;
}

function sendMail(MandrillTransport $transport, FileSystem $fileSystem) {
    $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>');
    
    $file = $fileSystem->getFile('/path/to/image.png');
    
    $message->addAttachement($file, 'image/png');
    
    try {
        $transport->send($message);
    } catch (MailException $exception) {
        
    }
}

Related Modules

Installation

You can use Composer to install this library.

composer require ride/lib-mail