Skip to content

peter-gribanov/sendmail

Repository files navigation

sendmail

Latest Stable Version Total Downloads Build Status Coverage Status Scrutinizer Code Quality SensioLabs Insight StyleCI License

Package for send mails.

Examples

Send mail from mail() function

Send one message by the PHP function mail()

use Sendmail\Message;
use Sendmail\Sender\Mail;

$message = new Message();
$message
    ->setTo('[email protected]')
    ->setSubject('Example subject')
    ->setText('Example message');
$sender = new Mail();
$sender->send($message);

Send mail from SMTP

Connect to SMTP server and push mails into him

use Sendmail\Queue;
use Sendmail\Message;
use Sendmail\Sender\Smtp;
use Sendmail\Sender\Smtp\Exception;

$message1 = new Message();
$message1
    ->setTo('[email protected]')
    ->setSubject('Example subject 1')
    ->setText('Example message 1')
    // email of the sender
    ->setFrom('[email protected]', 'Sender');

$message2 = clone $message1;
$message2
    ->setTo('[email protected]')
    ->setSubject('Example subject 2')
    ->setText('Example message 2');

// sending messages to the queue via a direct connection to the SMTP server
$queue = new Queue(new Smtp('example.com', 25, 'username', 'password'));
$queue
    ->add($message1)
    ->add($message2);

try {
    // send all messages
    var_dump($queue->send());
} catch (Exception $e) {
    // SMTP dialogue
    echo $e->getDialogue()->getLog();
}

$queue->clear();

Creation mailing list

use Sendmail\Queue;
use Sendmail\Message;
use Sendmail\Sender\Mail;

$message = new Message();
$message
    ->setSubject('Example subject')
    ->setText('<h1>Example message.<h1><p>You can remove this message.</p>')
    // email of the sender
    ->setFrom('[email protected]')
    // send email in HTML format
    ->inHTML();

$queue = new Queue(new Mail());
// add to queue a letter addressed to multiple recipients
$queue->notify(
    array(
        '[email protected]',
        '[email protected]',
        '[email protected]'
    ),
    $message
);

$queue->send();
$queue->clear();