Mailing API
Mailing API
- Configuration
- Basic Usage
- Embedding Inline Attachments
- Mail & Local Development
- Working along with the classic Mailer Helper
Configuration
The new Mailing API provides a clean, simple API over the popular SwiftMailer library. The mail configuration file is app/config/mail.php, and contains options allowing you to change your SMTP host, port, and credentials, as well as set a global from address for all messages delivered by the library. You may use any SMTP server you wish. If you wish to use the PHP mail function to send mail, you may change the driver to mail in the configuration file. A sendmail driver is also available.
Basic Usage
The Mailer::send method may be used to send an e-mail message:
Mailer::send('Emails/Welcome', $data, function($message)
{
$message->to('foo@example.com', 'John Smith')->subject('Welcome!');
});
The first argument passed to the send method is the name of the view that should be used as the e-mail body. The second is the $data that should be passed to the view, and the third is a Closure allowing you to specify various options on the e-mail message.
Note: A $message variable is always passed to e-mail views, and allows the inline embedding of attachments. So, it is best to avoid passing a message variable in your view payload.
You may also specify a plain text view to use in addition to an HTML view:
Mailer::send(array('html.view', 'text.view'), $data, $callback);
Or, you may specify only one type of view using the html or text keys:
Mailer::send(array('text' => 'view'), $data, $callback);
You may specify other options on the e-mail message such as any carbon copies or attachments as well:
Mailer::send('Emails/Welcome', $data, function($message)
{
$message->from('us@example.com', 'Nova Framework');
$message->to('foo@example.com')->cc('bar@example.com');
$message->attach($pathToFile);
});
When attaching files to a message, you may also specify a MIME type and / or a display name:
$message->attach($pathToFile, array('as' => $display, 'mime' => $mime));
Note: The message instance passed to a Mail::send Closure extends the SwiftMailer message class, allowing you to call any method on that class to build your e-mail messages.
Embedding Inline Attachments
Embedding inline images into your e-mails is typically cumbersome; however, Nova Framework provides a convenient way to attach images to your e-mails and retrieving the appropriate CID.
Embedding An Image In An E-Mail View
<body>
Here is an image:
<img src="<?php echo $message->embed($pathToFile); ?>">
</body>
Embedding Raw Data In An E-Mail View
<body>
Here is an image from raw data:
<img src="<?php echo $message->embedData($data, $name); ?>">
</body>
Note that the $message variable is always passed to e-mail views by the Mail class.
Mail & Local Development
When developing an application that sends e-mail, it's usually desirable to disable the sending of messages from your local or development environment. To do so, you may either call the Mailer::pretend method, or set the pretend option in the app/Config/Mail.php configuration file to true. When the mailer is in pretend mode, messages will be written to your application's log files instead of being sent to the recipient.
Enabling Pretend Mail Mode
Mailer::pretend();
API preservation - Working along with the classic Mailer Helper
The Mailing API, being designed for the New Style APIs, will work along with the classic Mailer Helper, with no conflict between, they being absolutely independent. Then there will be no API break.
Also, it is possible to use the Mailing API while using also the Classic APIs.
Mailing API的更多相关文章
- HTTP methods 与 RESTful API
Note GET, primarily used to select resources. Other options for an API method include: POST, primari ...
- WHM API 1 - createacct
WHM API 1 - createacct Skip to end of metadata Created by Sync User, last modified on Sep 29, ...
- [转]How To Send Transactional Email In A NodeJS App Using The Mailgun API
https://www.npmjs.com/package/mailgun-js 本文转自:https://www.mailgun.com/blog/how-to-send-transactional ...
- 使用JMeter进行RESTful API测试
使用JMeter进行RESTful API测试 在哪里设置实现最优脚本重用的属性 由于支持云的应用程序通常可以轻松.快速地进行复制和部署,所以可以在多种环境中对其进行测试.如果您需要在多个环境中测试和 ...
- Video for Linux Two API Specification Revision 2.6.32【转】
转自:https://www.linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/spec-single/v4l2.html Video for ...
- Video for Linux Two API Specification revision0.24【转】
转自:http://blog.csdn.net/jmq_0000/article/details/7536805#t136 Video for Linux Two API Specification ...
- [转]Creating Mailing Labels in SQL Server Reporting Services (rdlc 数据1页 2竖排 显示)
本文转自:http://blogs.wrox.com/article/creating-mailing-labels-in-sql-server-reporting-services/ Most wo ...
- 干货来袭-整套完整安全的API接口解决方案
在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API大量存在,安全性令人堪优 在以前WEB API概念没有很普及的时候,都采用自已定义的接口和结构,对 ...
- 12306官方火车票Api接口
2017,现在已进入春运期间,真的是一票难求,深有体会.各种购票抢票软件应运而生,也有购买加速包提高抢票几率,可以理解为变相的黄牛.对于技术人员,虽然写一个抢票软件还是比较难的,但是还是简单看看123 ...
随机推荐
- HDU 4009 Transfer water 最小树形图
分析:建一个远点,往每个点连建井的价值(单向边),其它输水线按照题意建单向边 然后以源点为根的权值最小的有向树就是答案,套最小树形图模板 #include <iostream> #incl ...
- UVAlive3662 Another Minimum Spanning Tree 莫队算法
就是莫队的模板题 /* Memory: 0 KB Time: 1663 MS Language: C++11 4.8.2 Result: Accepted */ #include<cstdio& ...
- 【C/C++运行时库】 /MT /MTd /MD /MDd对C/C++运行库的影响
欢迎转载 转载请注明出处:http://www.cnblogs.com/cuish/p/3146937.html 测试VS中[项目属性]-[C/C++]-[代码生成]选项中的[运行库]- [ /MT, ...
- HGE初始化状态设置
HGE_FRAMEFUNC: 最重要的设置,每个HGE应用必须设置.游戏的主循环就是他了.类型为bool*(),返回真那么主循环退出,游戏也就结束了.否则进行必要的处理后返回假.必须在调用进入 ...
- 【译】 AWK教程指南 9读取命令行上的参数
大部分的应用程序都允许使用者在命令之后增加一些选择性的参数.执行awk时这些参数大部分用于指定数据文件文件名,有时希望在程序中能从命令行上得到一些其它用途的数据.本小节中将叙述如何在awk程序中取用这 ...
- 未能加载文件或程序集“WcfService”或它的某一个依赖项。试图加载格式不正确的程序。
“/”应用程序中的服务器错误. 未能加载文件或程序集“WcfService”或它的某一个依赖项.试图加载格式不正确的程序. 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息, ...
- 利用过采样技术提高ADC测量微弱信号时的分辨率
1. 引言 随着科学技术的发展,人们对宏观和微观世界逐步了解,越来越多领域(物理学.化学.天文学.军事雷达.地震学.生物医学等)的微弱信号需要被检测,例如:弱磁.弱光.微震动.小位移.心电.脑电等[1 ...
- 2015上海网络赛 A Puzzled Elena
题意:给定一棵树,求这个节点的所有子树中包括他本身与它互质的节点的个数. 解题思路:题利用dfs序+容斥原理+前缀和性质解决.题目中要求每个结点,和多少个它的子结点互素.如果每次为了求一个点去跑一遍d ...
- ubuntu 的 apt-get update 出现404错误时,ubuntu 版本也 end of life 了的解决方案
xmodulo.com/how-to-fix-apt-get-update-error-on-ubuntu.html 如果是依赖没找到,可以用 sudo apt-get install -f 先补齐依 ...
- android微信分享遇到的问题
1.WXWebpageObject.description 长度不能超过1024 2.若回调返回BaseResp.ErrCode.ERR_AUTH_DENIED(用户拒绝),请检查AppID是否填写正 ...