oligriffiths/emails-component

适用于 Nooku 框架的电子邮件组件

0.0.3 2015-01-14 23:09 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:08:09 UTC


README

#Nooku 邮件组件

这个组件背后的想法非常简单,即在 Nooku 中标准化发送模板化电子邮件。

目前,所有电子邮件发送都在每个组件中手动处理。这既不能提供品牌化外发电子邮件的机会,也无法进行任何类型的数据合并。这个组件可以处理这两者。

##1. 发送电子邮件

第一步是实例化电子邮件分发器

$dispatcher = $this->getObject('com://oligriffiths/emails.dispatcher.email', /* $config, optional*/);

$config 是可选的,一些默认值是从应用程序 /config/bootstrapper.php 中提取的。默认值如下:

* template' 		=> 'default',				//the "wrapping" template to use
* layout' 			=> 'default',				//the "layout" to use if loading an email layout from the filesystem
* content' 			=> null,					//email content
* content_txt	 	=> null,					//custom txt email content
* content_html	 	=> null,					//custom html email content
* from_email 		=> bootstrapper->mailfrom,
* from_name	 		=> bootstrapper->fromname,
* mailer 			=> bootstrapper->mailer,    //one of smtp/sendmail/mail
* sendmail			=> bootstrapper->sendmail,  //sendmail location
* smtp_auth 		=> bootstrapper->smtpauth,
* smtp_user 		=> bootstrapper->smtpuser,
* smtp_pass 		=> bootstrapper->smtppass,
* smtp_host 		=> bootstrapper->smtphost,
* smtp_port 		=> bootstrapper->smtpport,
* smtp_security 	=> bootstrapper->smtpsecure

所有这些都可以在实例化对象时覆盖,并作为第二个参数 $config 作为数组传递。

实例化后,发送电子邮件非常简单

$dispatcher->send(array(
	'recipient_email' => 'recipient@email.com', 
	'subject' => 'My subject', 
	'content' => "This is my email"
	'layout' => 'my_email' 	//Either supply content OR layout, not both, point 2 see below
));

发送()所需的最小参数是 recipient_emailsubject,以及 contentlayout 之一,但您可能还需要提供其他参数。完整的列表如下,其中大多数都是不言自明的。

* from_email
* from_name
* recipient_email
* recipient_name
* recipients 		//array of recipients, keys being email address, value being name
* subject
* content			//email content
* content_txt		//custom txt email content
* content_html		//custom html email content
* layout			//an email layout to load from the file system, specifiy EITHER content OR layout

send() 返回的值是一个布尔值,表示电子邮件是否成功发送。

##2. 正文副本

电子邮件的正文副本可以通过两种方式提供,要么是布局模板,要么是字符串。

###布局模板

这是推荐的方法。您可以在文件系统中创建电子邮件布局,并在发送电子邮件时引用这些布局。电子邮件布局模板必须放置在您的活动站点模板中,作为模板覆盖,例如 /applications/site/public/theme/themename/templates/emails/email/{name}.{format}.php

  • {name} - 是布局的名称,然后作为 'layout' 属性传递给 send() 方法或作为实例化分发器时的选项
  • {format} - txt 或 html,用于纯文本或 HTML 电子邮件

将来将添加支持从另一个组件中加载这些模板的功能,以便电子邮件模板可以与组件捆绑在一起。

###字符串模板

将电子邮件内容作为字符串传递,可以是 content_html / content_txt 或仅 content

content_htmlcontent_txt 将为 HTML 和 txt 电子邮件定义特定内容,content 将使用相同的内容,并且将在 html 版本上运行 nl2br()

##3. 邮件合并

该组件将自动在电子邮件正文中合并传递给 send() 的任何键以及上述方法中列出的默认值。

邮件合并的格式为 {{VARIABLE}},大写,例如 {{FROM_EMAIL}}

##4. 传输机制

此组件在内部使用 SwiftMailer,并支持三种主要传输机制

  • smtp
  • sendmail
  • mail

##5. 其他事项

遵循代码,深入研究查看代码!

欢迎拉取请求

Twitter: @oligriffiths