2017 © Pedro Peláez
 

symfony-bundle mailer-bundle

Basic mailer

image

grizzlylab/mailer-bundle

Basic mailer

  • Thursday, June 7, 2018
  • by grizzlylab
  • Repository
  • 1 Watchers
  • 3 Stars
  • 2,594 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 3 Open issues
  • 11 Versions
  • 14 % Grown

The README.md

GrizzlylabMailerBundle

Symfony bundle to send an e-mail with just one line of code. It uses "symfony/twig-bundle" and "symfony/swiftmailer-bundle"., (*1)

1. Requirements

Since 2.0, PHP 7.4+ is required and dependency "symfony/twig-bundle" replaces "symfony/templating". It means this bundle now only supports Twig., (*2)

Since 1.3, important changes have been made to dependencies., (*3)

Since 1.2.1, PHP 7.1+ is required. Before this release, PHP 5.4 is the minimum required., (*4)

2. Installation

Run the command below to install via composer, (*5)

composer require grizzlylab/mailer-bundle "~2.0"

Then enable it in your kernel:, (*6)

// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        //...
        new Grizzlylab\Bundle\MailerBundle\GrizzlylabMailerBundle()
        //...

3. Configuration

Configure parameters.yml

#app/config/parameters.yml (advice, set it in "parameters.yml.dist" also)
    #...
    mailer_sender_address: noreply@domain.com #required, will be injected in mailer service
    mailer_sender_name: GrizzlyLab #required, will be injected in mailer service
    #...

Configure SwiftMailer (if not already done)

#SwifMailer Configuration
swiftmailer:
    transport:      "%mailer_transport%"
    encryption:     "%mailer_encryption%"
    auth_mode:      "%mailer_auth_mode%"
    host:           "%mailer_host%"
    port:           "%mailer_port%"
    username:       "%mailer_user%"
    password:       "%mailer_password%"
    spool:          { type: memory }
    sender_address: "%mailer_sender_address%"

OPTIONAL: You can use your new parameters (defined in parameters.yml) in your SwiftMailer configuration

This way, even if you send an e-mail without "grizzlylab_mailer", the "sender_address" will be the same., (*7)

#app/config/config.yml
#SwifMailer Configuration
swiftmailer:
    #...
    sender_address: "%mailer_sender_address%"
    #...

4. Use

1. Content:
a) By default, the $content argument is the location of a Twig template:
$container->get('grizzlylab_mailer')->send('@AcmeUser/Mail/awesome.txt.twig', $emails);

Rules inside your Twig template: * use the first line as the subject * use the rest as the body, (*8)

b) If you just want to use a simple string, set the argument $contentIsATemplate to false
$container->get('grizzlylab_mailer')->send('@AcmeUser/Mail/awesome.txt.twig', $emails, null, [], false);
2. More examples
//send($content, $addresses, $subject = null, array $templateParameters = [], $contentIsATemplate = true, array $sender = null)
//If the content is a template and if the subject is null, we use the first line of the template as the subject && the rest as the body

// for a single recipient, second arguement is a string (e.g. 'recipient@domain.com')
$this->container->get('grizzlylab_mailer')->send($content, $address);

// for multiple recipients, second arguement is an array
$this->container->get('grizzlylab_mailer')->send($content, $addresses);

// you can override the sender 
$sender = ['address' => adresse@domain.com, 'name' => 'GrizzlyLab'];
$this->container->get('grizzlylab_mailer')->send($content, $addresses, $sender);

// the return value is the number of recipients who were accepted for delivery
$numberOfAcceptedRecipients = $this->container->get('grizzlylab_mailer')->send($content, $addresses, $sender);

That's it!, (*9)

License

This bundle is under the MIT license., (*10)

The Versions

07/06 2018

dev-master

9999999-dev https://github.com/grizzlylab/MailerBundle

Basic mailer

  Sources   Download

MIT

The Requires

 

by Jean-Louis Pirson

swiftmailer mailer

21/04 2017

1.2.2

1.2.2.0 https://github.com/grizzlylab/MailerBundle

Basic mailer

  Sources   Download

MIT

The Requires

 

by Jean-Louis Pirson

swiftmailer mailer

21/04 2017

1.2.1.3

1.2.1.3 https://github.com/grizzlylab/MailerBundle

Basic mailer

  Sources   Download

MIT

The Requires

 

by Jean-Louis Pirson

swiftmailer mailer

21/04 2017

1.2.1.2

1.2.1.2 https://github.com/grizzlylab/MailerBundle

Basic mailer

  Sources   Download

MIT

The Requires

 

by Jean-Louis Pirson

swiftmailer mailer

21/04 2017

1.2.1.1

1.2.1.1 https://github.com/grizzlylab/MailerBundle

Basic mailer

  Sources   Download

MIT

The Requires

 

by Jean-Louis Pirson

swiftmailer mailer

21/04 2017

1.2.1

1.2.1.0 https://github.com/grizzlylab/MailerBundle

Basic mailer

  Sources   Download

MIT

The Requires

 

by Jean-Louis Pirson

swiftmailer mailer

17/03 2017

1.2

1.2.0.0 https://github.com/grizzlylab/MailerBundle

Basic mailer

  Sources   Download

MIT

The Requires

 

by Jean-Louis Pirson

swiftmailer mailer

25/08 2016

1.1

1.1.0.0 https://github.com/grizzlylab/MailerBundle

Basic mailer

  Sources   Download

MIT

The Requires

 

by Jean-Louis Pirson

swiftmailer mailer

22/08 2016

1.0.2

1.0.2.0 https://github.com/grizzlylab/MailerBundle

Basic mailer

  Sources   Download

MIT

The Requires

 

by Jean-Louis Pirson

swiftmailer mailer

09/04 2016

1.0.1

1.0.1.0 https://github.com/grizzlylab/MailerBundle

Basic mailer

  Sources   Download

MIT

The Requires

 

by Jean-Louis Pirson

swiftmailer mailer

17/10 2015

1.0.0

1.0.0.0 https://github.com/grizzlylab/MailerBundle

Basic mailer

  Sources   Download

MIT

The Requires

 

by Jean-Louis Pirson

swiftmailer mailer