Ride: Mail Library
Mail library of the PHP Ride framework., (*1)
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 ., (*2)
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., (*3)
MimePart
The MimePart class is internally used to add attachments to a MailMessage.
You can use it manually to create a custom multipart message., (*4)
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., (*5)
A generic implentation is provided is this library through the SimpleTransport class.
This uses the PHP functions to send a mail., (*6)
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., (*7)
Code Sample
Check the following code sample to some of the possibilities of this library., (*8)
<?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>
..., (*9)
</body></html>');
$file = $fileSystem->getFile('/path/to/image.png');
$message->addAttachement($file, 'image/png');
try {
$transport->send($message);
} catch (MailException $exception) {
}
}
Installation
You can use Composer to install this library., (*10)
composer require ride/lib-mail