myzend / email
此包的最新版本(0.9.3.1)没有提供许可证信息。
MyZend Email是一个ZF2模块,用于管理使用模板发送邮件的过程。您也可以依赖MailJet/Gmail smtp。
0.9.3.1
2013-08-01 23:18 UTC
This package is not auto-updated.
Last update: 2024-09-24 05:15:54 UTC
README
简介
MyZend Email是一个ZF2模块,用于管理使用模板发送邮件的过程。
它封装了Zend\Mail\Message以保持其简单易用。
此模块使用
- 带有模板的html电子邮件正文
- 带有模板的主题
- 带有模板的txt电子邮件正文(html的替代品)
用法
/*
* 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);
安装
每个模块都将有自己的电子邮件模板。
将这些配置添加到 module/Application/config/module.config.php
'email' => array(
"template_path_stack" => array(
__DIR__ . "/../view/email/"
),
),
电子邮件布局 - 将此结构添加到您的应用程序模块中
module/Application/view/email/layout/html/default.phtml
module/Application/view/email/layout/txt/default.phtml
模块 - 将这些配置添加到 module/MODULE/config/module.config.php
'email' => array(
"template_path_stack" => array(
__DIR__ . "/../view/email/"
),
),
电子邮件模板 - 将此结构添加到您的模块中
module/MODULE/view/email/html/MODULE/example.phtml
module/MODULE/view/email/subject/MODULE/example.phtml
module/MODULE/view/email/txt/MODULE/example.phtml
现在,您可以使用布局和模板了
$email = $this->email->create();
$email->setTemplateName("MODULE/example");
$email->addTo("ignacio@yourproject.net", "Ignacio Pascual");
$this->email->send($email);
配置文件
在config/autoload文件夹下设置您的配置 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
)
)
);
如何避免邮件进入垃圾邮件文件夹(SMTP中继)
您可以在服务器端花费数小时工作,但最简单的解决方案是我找到的,即设置您的Web应用程序使用SMTP提供者中继。
MailJet (www.mailjet.com)
...
'relay' => array(
'active' => true,
'host' => 'in.mailjet.com',
'port' => '',
'username' => 'bc8c7xxxxxxxxxxxxxxxxxxxxxxxx42b',
'password' => 'bc8c7xxxxxxxxxxxxxxxxxxxxxxxx42b',
'ssl' => ''
)
GMAIL(使用您的Gmail账户)
...
'relay' => array(
'active' => true,
'host' => 'smtp.gmail.com',
'port' => '587',
'username' => 'youremail@gmail.com',
'password' => 'xxxxxxxxxx',
'ssl' => 'tls'
)