asgard/email

v0.3.1 2016-05-13 11:31 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:50:31 UTC


README

#Email

Build Status

##安装 如果您正在处理一个 Asgard 项目,您不需要安装此库,因为它已经是标准库的一部分。

composer require asgard/email 0.*

##Asgard 框架中的使用

###配置

在 config/ 目录下的配置文件中添加

#smtp
email:
	driver: Asgard\Email\SwiftEmail
	transport => smtp
	username  => ...
	password  => ...
	security  => ssl #or null
	host      => ...
	port      => ...
#sendmail
email:
	driver: Asgard\Email\SwiftEmail
	transport => sendmail
	command  => ...
#mail()
email:
	driver: Asgard\Email\SwiftEmail

###服务

$email = $container['email'];

容器 常常可以通过方法参数或通过 容器感知 对象访问。您也可以使用 单例,但不推荐使用。

##Asgard 框架之外的使用

###配置

#smtp
$config = [
	'transport' => 'smtp',
	'username'  => '...',
	'password'  => '...',
	'security'  => 'ssl', #or null
	'host'      => '...',
	'port'      => '...',
];
#sendmail
$config = [
	'transport' => 'sendmail',
	'command'  => '...',
];
#mail()
$config = [];

###实例

$email = new \Asgard\Email\SwiftEmail;
$email->transport($config);

##发送电子邮件

$email->send(function($message) {
	$message->to('bob@example.com');
	$message->from('joe@example.com');
	$message->cc('joe@example.com');
	$message->bcc('joe@example.com');
	$message->text('hello!');
	$message->html('<h1>hello!</h1>');
});

$message 继承自 \Swift_Message,因此您可以使用其任何方法。 查看其文档

##附加文件

直接附加文件

$email->send(function($message) {
	//...
	$message->attachFile('/path/to/file.jpg', 'myhouse.jpg', 'image/jpeg');
});

或数据

$email->send(function($message) {
	//...
	$message->attachData($data, 'myhouse.jpg', 'image/jpeg');
});

##嵌入图片

直接嵌入图片

$email->send(function($message) {
	//...
	$message->html('<h1>Hello!</h2> See my house '.$message->embedFile('/path/to/file.jpg', 'myhouse.jpg', 'image/jpeg'));
});

或数据

$email->send(function($message) {
	//...
	$message->html('<h1>Hello!</h2> See my house '.$message->embedData($data, 'myhouse.jpg', 'image/jpeg'));
});

##伪造邮件

对于测试和开发,您可能想使用伪造的邮件而不是发送真实的电子邮件。伪造邮件简单地在本地编写。

配置

email:
	driver: Asgard\Email\FakeEmail
	file: storage/email.txt

除此之外,使用方法与其他电子邮件相同。

###贡献

请将所有问题和拉取请求提交到 asgardphp/asgard 仓库。

许可

Asgard 框架是开源软件,受 MIT 许可证 许可。