A simple mailer, allows you to create and send emails by key. Messages can be stored in different storages. Third-party mailers act as transport.
$ composer require anper/mailer
use Anper\Mailer\Transport\NullTransport;
use Anper\Mailer\Storage\MemoryStorage
use Anper\Mailer\Mailer;
$storage = new MemoryStorage([
'hello' => [
'subject' => 'Hello',
'body' => 'Hello World!',
'from' => 'from@example.com',
'to' => 'user@example.com',
],
]);
$mailer = new Mailer(new NullTransport(), $storage);
$mailer->send('hello');
// or you can modify message
$mailer->get('hello')
->addTo('foo@example.com')
->send();
- subject
- body
- from
- to
- cc
- bcc
- reply_to
- sender
- return_path
- attachments
- headers
- priority
- content_type
- charset
- Storages
- Transports
You can pass context to the storage, for example, variables for the template in twig storage.
$context = [
'foo' => 'bar'
];
$mailer->send('hello', $context);
// or
$message = $mailer->get('hello', $context);
use Anper\Mailer\Subscriber\Defaults;
$defaultMessageParameters = [
'from' => 'admin@example.com',
'content_type' => 'text/plain',
];
$defaultContext = [
'teem' => 'Example Team',
];
$subscriber = new Defaults($defaultMessageParameters, $defaultContext);
$mailer->getDispatcher()
->addSubscriber($subscriber);
$ composer test
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.