2017 © Pedro Peláez
 

library sendgrid-transport-module

Zend Framework 2 Module that provides SendGrid as a Transport for Mail.

image

andrebian/sendgrid-transport-module

Zend Framework 2 Module that provides SendGrid as a Transport for Mail.

  • Saturday, February 25, 2017
  • by andrebian
  • Repository
  • 1 Watchers
  • 0 Stars
  • 196 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 15 % Grown

The README.md

SendGrid Transport Module for Zend Framework

Latest Stable Version Total Downloads Latest Unstable Version License Codacy Badge Codacy Badge, (*1)

This module provide SendGrid as a transport for transactional e-mail in Zend Framework 2., (*2)

INSTALLING

composer require andrebian/sendgrid-transport-module, (*3)

After install follow one of these steps:, (*4)

1) Copy the contents file vendor/andrebian/sendgrid-transport-module/mail.global.php.dist and put it in your config/autoload/mail.global.php., (*5)

2) If this file does not exists in your application, just copy the entire file and place into your config/autoload removing the .dist extension., (*6)

Then put your SendGrid API Key. To get your API Key, please visit https://sendgrid.com/docs/Classroom/Send/How_Emails_Are_Sent/api_keys.html, (*7)

// config/autoload/mail.global.php

return array(
    'mail' => array(
        'sendgrid' => array(
            'api_key' => 'YOUR_API_KEY',
        )
    )
);

After all, you must register SendGridTransportModule in your config/application.config.php., (*8)

// config/application.config.php
return [
    'modules' => [
        'YourPreviousModules',
        'SendGridTransportModule'
    ],
    'module_listener_options' => [
        'module_paths' => [
            './module',
            './vendor',
        ],
        'config_glob_paths' => [
            'config/autoload/{{,*.}global,{,*.}local}.php',
            'module/{*}/config/autoload/{{,*.}global,{,*.}local}.php',
        ],
    ]
];

USAGE

Via Service

By default, when the SendGridTransportModule is loaded a service is registered and ready to use., (*9)

// In a Controller
$sendGridTransport = $this->getServiceLocator()->get('SendGridTransport');

Full example with service

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Mail;

class SomeController extends AbstractActionController
{
    public function someAction()
    {
        $mail = new Mail\Message();
        $mail->setBody('This is the text of the email.');
        $mail->setFrom(new Mail\Address('test@example.org', 'Sender\'s name'));
        $mail->addTo(new Mail\Address('some@address.com', 'User Name'));
        $mail->setSubject('TestSubject');

        $sendGridTransport = $this->getServiceLocator()->get('SendGridTransport');
        $sendGridTransport->send($mail);

        return new ViewModel();
    }
}

Directly

If you need more control, you can use the library anywhere you want., (*10)

use SendGrid;
use SendGridTransportModule\SendGridTransport;

class SomeControllerOrServiceOrHelper 
{
    public function someMethod()
    {
        $mail = new Mail\Message();
        $mail->setBody('This is the text of the email.');
        $mail->setFrom(new Mail\Address('test@example.org', 'Sender\'s name'));
        $mail->addTo(new Mail\Address('some@address.com', 'User Name'));
        $mail->setSubject('TestSubject');

        $sendGrid = new SendGrid('YOUR_API_KEY');
        $sendGridEmail = new SendGrid\Email();
        $sendGridTransport = new SendGridTransport($sendGrid, $sendGridEmail);

        $sendGridTransport->send($mail);
    }
}

Is strongly recommended to use the already registered service., (*11)

CONTRIBUTING

You can contribute with this module suggesting improvements, making tests and reporting bugs. Use issues for that., (*12)

LICENSE

MIT, (*13)

ERRORS

Report errors opening Issues., (*14)

The Versions

25/02 2017

dev-master

9999999-dev

Zend Framework 2 Module that provides SendGrid as a Transport for Mail.

  Sources   Download

MIT

The Requires

 

The Development Requires

zf2 module