Mail library of the PHP Ride framework.
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 .
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.
The MimePart class is internally used to add attachments to a MailMessage. You can use it manually to create a custom multipart message.
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.
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.
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) {
}
}
- ride/app-mail
- ride/app-mail-mandrill
- ride/lib-log
- ride/lib-mail-mandrill
- ride/lib-system
- ride/lib-validation
You can use Composer to install this library.
composer require ride/lib-mail