Giter VIP home page Giter VIP logo

mtmail's Introduction

E-mail module for Zend Framework

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads

Introduction

MtMail handles common activities surrounding sending e-mail from applications, mainly creating messages from templates, and sending them through transport adapters.

Features:

  • factory for creating e-mail messages
  • factory for e-mail transport adapters, service for one-line dispatch
  • rendering templates from phtml files, using Laminas\View and PhpRenderer
  • rendering templates with layouts
  • plugins for various common tasks: from setting default headers to generating plaintext version of HTML message
  • plugin support via dedicated plugin managers

Installation

Installation is supported via Composer:

$ composer require mtymek/mt-mail

Creating e-mails

Configuration

By default MtMail doesn't require any extra configuration. It will use Laminas\View to render templates accessible by your application.

Usage

Creating message from controller:

$mailService = $this->getServiceLocator()->get(\MtMail\Service\Mail::class);

$headers = [
    'to' => '[email protected]',
    'from' => '[email protected]',
];
$variables = [
    'userName' => 'John Doe',
];
$message = $mailService->compose($headers, 'application/mail/welcome.phtml', $variables);

This snippet will create a message, compose it with $headers and HTML body rendered from welcome.phtml template (injected with $variables array).

Layouts

In order to give your e-mails common layout, you have to enable "Layout" plugin and tell it where to look for layout template:

return [
    'mt_mail' => [
        'composer_plugins' => [
            'Layout',
        ],
        'layout' => 'application/mail/layout.phtml',
    ],
];

For more info about composing e-mail messages, check [the documentation](doc/Composing messages.md). You can also check [documentation for plugins](doc/Composer Plugins.md).

Sending e-mails

Configuration

Update your application config:

return [
    'mt_mail' => [
        'transport' => \Laminas\Mail\Transport\Smtp::class,
        'transport_options' => [
            'host' => 'some-host.com',
            'connection_class' => 'login',
            'connection_config' => [
                'username' => 'user',
                'password' => 'pass',
                'ssl' => 'tls',
            ],
        ],
    ],
];

Usage


Add following code to your controller:

// create and configure message
$message = new Message();
$message->addTo('[email protected]');
// ...

// send!
$mailService = $this->getServiceLocator()->get(\MtMail\Service\Mail::class);
$mailService->send($message);

For more info on sending e-mails, check [the documentation](doc/Sending messages.md).

mtmail's People

Contributors

mtymek avatar ojhaujjwal avatar apaikens avatar jaapio avatar samsonasik avatar rpencis avatar stefanotorresi avatar mrova avatar robob4him avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.