View on GitHub

EmailZF2

Send Email in zend framework 2, simple & easy

download .ZIPdownload .TGZ

Welcome to EmailZF2.

Version 1.0

ITALIANO

Modulo che consente l'invio di email in zend framework 2 con o senza template.

Installazione

Per l'installazione usa composer composer.

php composer.phar require email-zf2/emailzf2:dev-master

Se avete composer installato:

composer require email-zf2/emailzf2:dev-master

Post Installazione

Una volta effettuata l'installazione con composer passiamo alla configurazione.

<?php
return array(
    'email' => array(
        'credentials' => array(
            'from_mail' => 'support@domain.com',
            'from_name' => 'yourname',
        ),
        //use smtp or sendmail
        'transport' => 'sendmail',
        'smtp' => array(
            'host' => 'smtp.domain.com',
            'port' => 587,
            'connection_class' => 'login',
            'connection_config' => array(
                'ssl'      => 'tls',
                'username' => 'youremail',
                'password' => 'yourpassword'
            ),
        ),
    ),
);

In questo modo abbiamo appena creato il nostro file di configurazione. In questo file possiamo scegliere se mandare le email con sendmail installato sul server oppure inviare email utilizzando smtp. Se vuoi utilizzare sendmail lascia il file di configurazione cosi per come รจ.

Come si usa

Basta creare in qualsiasi modulo una cartella per salvare i template da usare per le email. Per convenzione mettiamo la cartella sotto il modulo Application.

Controller

$view = new ViewModel(array(
                'fullname' => 'Vincenzo Provenza',
            ));
$view->setTerminal(true);
$view->setTemplate('Application/view/emails/hello_world');
$this->mailerZF2()->send(array(
    'to' => 'email@domain.it',
    'subject' => 'This is subject'
), $view);
$view = new ViewModel(array(
                'fullname' => 'Vincenzo Provenza',
            ));
$view->setTerminal(true);
$view->setTemplate('Application/view/emails/hello_world');
$this->mailerZF2()->send(array(
    'to' => 'email@domain.com',
    'cc' => 'email2@domain.com'
    'subject' => 'This is subject'
), $view);
$view = new ViewModel(array(
                'fullname' => 'Vincenzo Provenza',
            ));
$view->setTerminal(true);
$view->setTemplate('Application/view/emails/hello_world');
$this->mailerZF2()->send(array(
    'to' => 'email@domain.com',
    'cc' => 'email2@domain.com'
    'bcc' => 'email3@domain.com'
    'subject' => 'This is subject'
), $view);

Template

<h4>Hi, <?= $fullname; ?></h4>

ENGLISH

Module which allows sending emails in Zend Framework 2 with or without template.

Installation

For the installation use composer composer.

php composer.phar require email-zf2/emailzf2:dev-master

If you have installed composer:

composer require email-zf2/emailzf2:dev-master

Post Installation

Once the installation with composer pass to the configuration.

<?php
return array(
    'email' => array(
        'credentials' => array(
            'from_mail' => 'support@domain.com',
            'from_name' => 'yourname',
        ),
        //use smtp or sendmail
        'transport' => 'sendmail',
        'smtp' => array(
            'host' => 'smtp.domain.com',
            'port' => 587,
            'connection_class' => 'login',
            'connection_config' => array(
                'ssl'      => 'tls',
                'username' => 'youremail',
                'password' => 'yourpassword'
            ),
        ),
    ),
);

In this way we have just created our configuration file. In this file we can choose whether to send emails with sendmail installed on the server or send email using smtp. If you want to leave the sendmail configuration file so as it is.

Usage

Just create any module in a folder to save the template to use for emails. By convention we put the folder in the Application Module.

Controller

$view = new ViewModel(array(
                'fullname' => 'Vincenzo Provenza',
            ));
$view->setTerminal(true);
$view->setTemplate('Application/view/emails/hello_world');
$this->mailerZF2()->send(array(
    'to' => 'email@domain.it',
    'subject' => 'This is subject'
), $view);
$view = new ViewModel(array(
                'fullname' => 'Vincenzo Provenza',
            ));
$view->setTerminal(true);
$view->setTemplate('Application/view/emails/hello_world');
$this->mailerZF2()->send(array(
    'to' => 'email@domain.com',
    'cc' => 'email2@domain.com'
    'subject' => 'This is subject'
), $view);
$view = new ViewModel(array(
                'fullname' => 'Vincenzo Provenza',
            ));
$view->setTerminal(true);
$view->setTemplate('Application/view/emails/hello_world');
$this->mailerZF2()->send(array(
    'to' => 'email@domain.com',
    'cc' => 'email2@domain.com'
    'bcc' => 'email3@domain.com'
    'subject' => 'This is subject'
), $view);

Template

<h4>Hi, <?= $fullname; ?></h4>