gribanov / sendmail
Library for send mail
v1.6.2
2017-11-28 14:31 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ~4.8
- satooshi/php-coveralls: ^1.0
- scrutinizer/ocular: ~1.2
Suggests
- ext-runkit: For using the runkit API in tests.
This package is auto-updated.
Last update: 2024-10-28 23:01:00 UTC
README
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('user@example.com') ->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('user1@example.com') ->setSubject('Example subject 1') ->setText('Example message 1') // email of the sender ->setFrom('sender@example.com', 'Sender'); $message2 = clone $message1; $message2 ->setTo('user2@example.com') ->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('sender@example.com') // send email in HTML format ->inHTML(); $queue = new Queue(new Mail()); // add to queue a letter addressed to multiple recipients $queue->notify( array( 'user1@example.com', 'user2@example.com', 'user3@example.com' ), $message ); $queue->send(); $queue->clear();