2017 © Pedro Peláez
 

library mailer

Wrapper around Swiftmailer

image

ronrademaker/mailer

Wrapper around Swiftmailer

  • Thursday, June 8, 2017
  • by RonRademaker
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,255 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 5 Versions
  • 3 % Grown

The README.md

Mailer

Wrapper around Swiftmail., (*1)

Usage

The mailer wrapper can be used without any knowledge of Swift Mailer, or by using the full power by creating your own Swift_Message., (*2)

Installation

composer require ronrademaker/mailer

Configuration

Assuming you'll want to register the mailer in a DIC, Symfony XML example:, (*3)



<container xmlns='http://symfony.com/schema/dic/services'
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  xsi:schemaLocation='http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd'>

  <parameters>
    <parameter key='mailer_twig.path'>[LOCATION OF YOUR TEMPLATES]</parameter>
    <parameter key='mailer_twig.options' type='collection'> 
      [ADD YOUR OPTIONS]
    </parameter>
  </parameters>

  <services>
    <service id='mailer_transport' class='Swift_Transport'>
      <factory class='Swift_SendmailTransport' method='newInstance'/>
    </service>
    <service id='mailer_swift' class='Swift_Mailer'>
      <factory class='Swift_Mailer' method='newInstance'/>
      <argument type='service' id='mailer_transport'/>
    </service>
    <service id='mailer_twig_loader' class='Twig_Loader_Filesystem'>
      <argument>%mailer_twig.path%</argument>
    </service>
    <service id='mailer_twig' class='Twig_Environment'>
      <argument type='service' id='mailer_twig_loader'/>
      <argument>%mailer_twig.options%</argument>
    </service>
    <service id='mailer' class='RonRademaker\Mailer\Mailer'>
      <argument type='service' id='mailer_twig'/>
      <argument type='service' id='mailer_swift'/>
    </service>
  </services>
</container>

Sending mails with twig template

Example template

{% block subject 'My Mail Subject' %}

{% block body_html %}


Some mail with HTML formatting, (*4)

{% endblock %} {% block body_text %} Some mail in boring plain text {% endblock %}

Send the mail

$mailer->sendEmail(['example@example.org' => 'Example Receiver'], 'sender@example.org' => 'Example Sender', 'my_twig_template');

Send a Swift Message

Create your message in $message and, (*5)

$mailer->sendMessage($message);

Retrieving receivers from objects

It is possible to use a Determiner to retrieve the receivers (email/name) from an email configuration. For instance from an object:, (*6)

``` php $profile = new Profile(); $profile->setEmail('foobarz@example.com'); $profile->setFullName('Foo Barz');, (*7)

$emailConfiguration = ['{{email}}' => '{{full_name'}}]; $determiner = new RonRademaker\Mailer\Receiver\Determiner(); $receiver = $determiner->getReceivers($profile, null, $emailConfiguration); // results in ['foobarz@example.com' => 'Foo Barz'];, (*8)

Or an object with chained field configuration:

``` php
$profile = new Profile();
$profile->setEmail('foobarz@example.com');
$profile->setFullName('Foo Barz');
$company = new Company();
$company->setContactperson($profile);

$emailConfiguration = ['email' => '{{contactperson.email}}', 'name' => '{{contactperson.full_name'}}];
$determiner = new RonRademaker\Mailer\Receiver\Determiner();
$receiver = $determiner->getReceivers($company, null, $emailConfiguration);
// results in ['email' => 'foobarz@example.com', 'name' => 'Foo Barz'];

NOTE: The determiner requires getters., (*9)

Or just hardcoded settings:, (*10)

php $emailConfiguration = ['email' => 'foobarz@example.com', 'name' => 'Foo Barz']; $determiner = new RonRademaker\Mailer\Receiver\Determiner(); $receiver = $determiner->getReceivers($object, null, $emailConfiguration); // results in ['email' => 'foobarz@example.com', 'name' => 'Foo Barz'];, (*11)

The Versions

08/06 2017

dev-master

9999999-dev

Wrapper around Swiftmailer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ron Rademaker

08/06 2017

1.2.0

1.2.0.0

Wrapper around Swiftmailer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ron Rademaker

29/12 2016

1.1.1

1.1.1.0

Wrapper around Swiftmailer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ron Rademaker

08/07 2016

1.1.0

1.1.0.0

Wrapper around Swiftmailer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ron Rademaker

24/11 2015

1.0.0

1.0.0.0

Wrapper around Swiftmailer

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ron Rademaker