anper/mailer

This package is abandoned and no longer maintained. No replacement package was suggested.

A simple mailer, allows you to create and send emails by key.

v0.1.4 2019-09-08 15:59 UTC

This package is auto-updated.

Last update: 2020-11-22 10:11:10 UTC


README

Software License Latest Version on Packagist Build Status Coverage Status

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.

Install

$ composer require anper/mailer

Usage

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();

Supports

  • subject
  • body
  • from
  • to
  • cc
  • bcc
  • reply_to
  • sender
  • return_path
  • attachments
  • headers
  • priority
  • content_type
  • charset

Packages

Context

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);

Defaults

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);

Test

$ composer test

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.