2017 © Pedro Peláez
 

library email

MyZend Email is a ZF2 module to manage the process of sending emails with templates. You could also realy on MailJet/Gmail smtp.

image

myzend/email

MyZend Email is a ZF2 module to manage the process of sending emails with templates. You could also realy on MailJet/Gmail smtp.

  • Friday, August 2, 2013
  • by ipascual
  • Repository
  • 2 Watchers
  • 7 Stars
  • 409 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 3 Open issues
  • 4 Versions
  • 1 % Grown

The README.md

MyZend / Email

Introduction

MyZend Email is a ZF2 module to manage the process of sending emails with templates., (*1)

It encapsulates Zend\Mail\Message to keep it a simple use., (*2)

This module uses * html email body with templates * subject with templates * txt email body with templates (alternative to html), (*3)

Usage

/*
 * Basic use
 */
$email = $this->email->create();
$email->addTo("ignacio@yourproject.net", "Ignacio Pascual");
$this->email->send($email);
/*
 * Admin mail
 */
$email = $this->email->create(array("html_content" => "this is a notice", "subject" => "error"));
$this->email->send($email);
/*
 * Using template variables
 */
$email = $this->email->create(array(
                            "name" => "I. Pascual",
                            "location" => "Barcelona"
                        ));
$email->setTemplateName("welcome");
$email->addTo("ignacio@yourproject.net", "Ignacio Pascual");
$this->email->send($email);
/**
 * Without templates
 */
$email = $this->email->create();
$email->setSubject("Test");
$email->setTextContent("Hi, this is a test!");
$email->setHtmlContent("<h1>Hi,</h1> <p>this is a test!</p>");
$email->addTo("ignacio@yourproject.net", "Ignacio Pascual");
$this->email->send($email);
/*
 * Optional arguments
 */
$email = $this->email->create();
$email->addTo("ignacio@yourproject.net", "Ignacio Pascual");

//From
$email->setFrom("postmaster@yourproject.com");
$email->setFromName("Do-Not-Reply");
//ReplyTo
$email->setReplyTo("support@yourproject.com");
$email->setReplyToName("Support Team");
//Layout
$email->setLayoutName("1column");
//Template
$email->setTemplateName("welcome");
//To
$email->addTo("other@example.com", "Mr. Other Recipient");
//Cc
$email->addCc("copy@example.com", "Mr. Copy Recipient");
//Bcc
$email->addBcc("other-copy@example.com", "Mr.Not Revealing");

$this->email->send($email);

Install

Every module will have its own email templates.
Add these config to module/Application/config/module.config.php
    'email' => array(
        "template_path_stack" => array(
                __DIR__ . "/../view/email/"
        ),
    ),

Email layout - Add this structure to your Application module, (*4)

    module/Application/view/email/layout/html/default.phtml
    module/Application/view/email/layout/txt/default.phtml
Module - Add these config to module/MODULE/config/module.config.php
    'email' => array(
        "template_path_stack" => array(
                __DIR__ . "/../view/email/"
        ),
    ),

Email templates - Add this structure to your MODULE, (*5)

    module/MODULE/view/email/html/MODULE/example.phtml
    module/MODULE/view/email/subject/MODULE/example.phtml
    module/MODULE/view/email/txt/MODULE/example.phtml
Now, you could easily use your layout and template
$email = $this->email->create();
$email->setTemplateName("MODULE/example");
$email->addTo("ignacio@yourproject.net", "Ignacio Pascual");
$this->email->send($email);

Config file

Setup your config under config/autoload folder module.email.local.php
return array(
    'email' => array(
        "active" => true,
        "defaults" => array(
                "layout_name" => "default",
                "from_email" => "no-reply@yourproject.com",
                "from_name" => "MyZend Project"
        ),
        "emails" => array(
            "support" => "ipascual@yourproject.com",
            "admin" => "ipascual@yourproject.com"
        ),
        'template_vars' => array(
            "company" => "MyZend Project",
            "slogan" => "",
            "baseUrl" => "http://www.yourproject.com"
        ),
        'relay' => array(
            'active'    => false,
            'host'      => '', 
            'port'      => '', // it could be empty
            'username'  => '',
            'password'  => '',
            'ssl'       => '' // it could be empty
        )
    )
);

How to avoid email going to SPAM folder (SMTP relay)

You could spend hours working on server side, but the easiest solution, that I've found, it's setup your web app for relaying on SMTP provider., (*6)

MailJet (www.mailjet.com)
...
        'relay' => array(
            'active'    => true,
            'host'      => 'in.mailjet.com', 
            'port'      => '',
            'username'  => 'bc8c7xxxxxxxxxxxxxxxxxxxxxxxx42b',
            'password'  => 'bc8c7xxxxxxxxxxxxxxxxxxxxxxxx42b',
            'ssl'       => ''
        )
GMAIL (using your gmail account)
...
        'relay' => array(
            'active'    => true,
            'host'      => 'smtp.gmail.com', 
            'port'      => '587',
            'username'  => 'youremail@gmail.com',
            'password'  => 'xxxxxxxxxx',
            'ssl'       => 'tls'
        )

The Versions

02/08 2013

dev-master

9999999-dev

MyZend Email is a ZF2 module to manage the process of sending emails with templates. You could also realy on MailJet/Gmail smtp.

  Sources   Download

by Ignacio Pascual

zf2 gmail mailjet html template html layout oop email

02/08 2013

0.9.3.1

0.9.3.1

MyZend Email is a ZF2 module to manage the process of sending emails with templates. You could also realy on MailJet/Gmail smtp.

  Sources   Download

by Ignacio Pascual

zf2 gmail mailjet html template html layout oop email

14/07 2013

0.9.1

0.9.1.0

MyZend Email is a ZF2 module to manage the process of sending emails with templates. You could also realy on MailJet/Gmail smtp.

  Sources   Download

by Ignacio Pascual

zf2 gmail mailjet html template html layout oop email

19/06 2013

v0.9

0.9.0.0

MyZend Email is a ZF2 module to manage the process of sending emails with templates.

  Sources   Download

by Ignacio Pascual