PHP code example of ride / lib-mail
1. Go to this page and download the library: Download ride/lib-mail 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 example snippets
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('[email protected]');
$transport->setDefaultReplyTo('[email protected]');
// 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('[email protected]');
return $transport;
}
function sendMail(MandrillTransport $transport, FileSystem $fileSystem) {
$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>');
$file = $fileSystem->getFile('/path/to/image.png');
$message->addAttachement($file, 'image/png');
try {
$transport->send($message);
} catch (MailException $exception) {
}
}