2017 © Pedro Peláez
 

library mailer

Pimple Service Provider for email and SwiftMailer services.

image

germania-kg/mailer

Pimple Service Provider for email and SwiftMailer services.

  • Monday, February 5, 2018
  • by germania-kg
  • Repository
  • 2 Watchers
  • 0 Stars
  • 43 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

Germania KG · Mailer

Pimple Service Provider for email and SwiftMailer services., (*1)

Packagist PHP version Build Status Scrutinizer Code Quality Code Coverage Build Status, (*2)

Installation

$ composer require germania-kg/mailer

Registering

<?php
use Germania\Mailer\MailerServiceProvider;

$dic = new \Pimple\Container;
$dic->register( new MailerServiceProvider );

Configuration

The configuration is an array with typical mail configration fields, each of them empty., (*3)

You can retrieve the configuration from the Pimple container like this:, (*4)

$dic->register( new MailerServiceProvider );
$config = $dic['Mailer.Config'];
print_r($config);
(
    [smtp] =>
    [port] =>
    [ssl] =>
    [user] => 
    [pass] =>
    [from_name] =>
    [from_mail] =>
    [to] =>
    [subject] =>
)

Configure on Instantiation

Pass a custom configuration to the MailerServiceProvider constructor. Register it to Pimple container as usual., (*5)

$mailer_service_provider = new MailerServiceProvider([
  'from_name' => 'John Doe',
  'from_mail' => 'me@test.com'
]);

$dic->register( $mailer_service_provider );
$config = $dic['Mailer.Config'];
print_r($config);
(
    [smtp] =>
    [port] =>
    [ssl] => 
    [user] => 
    [pass] =>
    [from_name] => John Doe
    [from_mail] => me@test.com
    [to] =>
    [subject] =>
)

Configure at Runtime

Two ways:, (*6)

  • After registering the ServiceProvider to Pimple (i.e. extending the Mailer.Config service definition)
  • Before registering, pre-defining the configuration in a Mailer.Config service definition

After registering with Pimple

$dic->register( new MailerServiceProvider() );
$dic->extend('Mailer.Config', function($default_config, $dic) {
  $new_config = array_merge($default_config, [
    'from_name' => 'John Doe',
    'from_mail' => 'me@test.com'
  ]);
  return $new_config;
});

Before registering with Pimple

$dic['Mailer.Config'] = function($dic) {
  return array(
    'from_name' => 'John Doe',
    'from_mail' => 'me@test.com'
  );
};

$dic->register( new MailerServiceProvider() );

Usage

Setup MailerServiceProvider:, (*7)

$dic->register( new MailerServiceProvider([
    'from_name' => 'John Doe',
    'from_mail' => 'me@test.com',
    'to'        => 'admin@test.com',
    'subject'   => 'Default subject'
]));

SwiftMailerCallable

<?php
use Germania\SwiftMailerCallable\SwiftMailerCallable;

// Grab the Mailer callable
$mailer = $dic[SwiftMailerCallable::class];
// DEPRECATED service name: 
$mailer = $dic['Mailer.Callable'];

// Send with subject and mail body
$result = $mailer("The subject", "

The mailtext, (*8)

"); # Override receipient address # previosuly set in Mailer.Config $result = $mailer("The subject", "

The mailtext, (*9)

", "admin@test.com");

SwiftMailer

See https://swiftmailer.symfony.com/docs/introduction.html, (*10)

<?php
use Germania\Mailer\SwiftMessageFactory;
use \Swift_Mailer;

// Grab Swiftmailer
$swift_mailer = $dic[Swift_Mailer::class];  

// Setup message
$message_factory = $dic[SwiftMessageFactory::class];
$message = $message_factory->createMessage();
$message->setBody("This is the mail body");

// This optional as we set it with Configuration
$message->setSubject( "Custom subject line" );

// Send message
$result = $swift_mailer->send( $message ));

Development

$ git clone https://github.com/GermaniaKG/Mailer.git
$ cd Mailer
$ composer install

Unit tests

Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:, (*11)

$ composer test
# or
$ vendor/bin/phpunit

The Versions

05/02 2018

dev-develop

dev-develop

Pimple Service Provider for email and SwiftMailer services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

05/02 2018

dev-master

9999999-dev

Pimple Service Provider for email and SwiftMailer services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

05/02 2018

1.0.5

1.0.5.0

Pimple Service Provider for email and SwiftMailer services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

08/12 2017

1.0.4

1.0.4.0

Pimple Service Provider for email and SwiftMailer services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

08/12 2017

1.0.3

1.0.3.0

Pimple Service Provider for email and SwiftMailer services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

15/11 2017

1.0.2

1.0.2.0

Pimple Service Provider for email and SwiftMailer services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

15/11 2017

1.0.1

1.0.1.0

Pimple Service Provider for email and SwiftMailer services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

15/11 2017

1.0.0

1.0.0.0

Pimple Service Provider for email and SwiftMailer services.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt