Mailing API

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的更多相关文章

  1. HTTP methods 与 RESTful API

    Note GET, primarily used to select resources. Other options for an API method include: POST, primari ...

  2. WHM API 1 - createacct

    WHM API 1 - createacct     Skip to end of metadata   Created by Sync User, last modified on Sep 29, ...

  3. [转]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 ...

  4. 使用JMeter进行RESTful API测试

    使用JMeter进行RESTful API测试 在哪里设置实现最优脚本重用的属性 由于支持云的应用程序通常可以轻松.快速地进行复制和部署,所以可以在多种环境中对其进行测试.如果您需要在多个环境中测试和 ...

  5. 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 ...

  6. Video for Linux Two API Specification revision0.24【转】

    转自:http://blog.csdn.net/jmq_0000/article/details/7536805#t136 Video for Linux Two API Specification ...

  7. [转]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 ...

  8. 干货来袭-整套完整安全的API接口解决方案

    在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API大量存在,安全性令人堪优 在以前WEB API概念没有很普及的时候,都采用自已定义的接口和结构,对 ...

  9. 12306官方火车票Api接口

    2017,现在已进入春运期间,真的是一票难求,深有体会.各种购票抢票软件应运而生,也有购买加速包提高抢票几率,可以理解为变相的黄牛.对于技术人员,虽然写一个抢票软件还是比较难的,但是还是简单看看123 ...

随机推荐

  1. 【jQuery】jQuery操作<input>的聚焦与全选其内容

    实现效果: 源代码: $(function() { $("#exist_code_remind").attr("style","display:non ...

  2. android捕获ListView中每个item点击事件

    转自:http://www.cnblogs.com/pswzone/archive/2012/03/10/2389275.html package com.wps.android;   import  ...

  3. Ofbiz 10.04 + eclipse 安装与配置

    1.下载 ofbiz 10.04:http://ofbiz.apache.org/download.html: 2.下载 freemarker-2.3.15 eclipse 插件(FreeMarker ...

  4. bug描述注意点

    一个好的错误跟踪系统包括了错误的必要信息,如果做得不好,会造成迷惑,并误导读者.好的故障描述应该包括十个基本部分:标题.项目.所属模块.优先级.重要性.异常等级.可重复性.现象.操作过程和附件. ①标 ...

  5. VTL说明文档

    关于这个指南 这个指南是针对Velocity模版语言(VTL)的说明.更多其它的信息,请参考Velocity用户指南(http://velocity.apache.org/engine/release ...

  6. 陈灯WGF双缓冲绘图框架

    “木丸子童屋”,专售各类儿童玩具,价格优惠,请大家多多支持:http://shop65552598.taobao.com/ WGF(windows graphic foundation)为window ...

  7. HDU 2476 String painter (区间DP)

    题意:给出两个串a和b,一次只能将一个区间刷一次,问最少几次能让a=b 思路:首先考虑最坏的情况,就是先将一个空白字符串刷成b需要的次数,直接区间DP[i][j]表示i到j的最小次数. 再考虑把a变成 ...

  8. 2014-02-27WPF学习笔记

    //StackPanel布局 //创建时间:11:33 页面布局:Orientation默认纵向:Vertical水平为:Horizontal <Button> <Button.Co ...

  9. C++&OpenCV中读取灰度图像到数组的两种

    如标题所言,此处是对于灰度图像而言 ///method 1 read the image data one by one for (int row = 0, i = 0;row < imgDst ...

  10. IntelliJ远程调试教程

    概述 对于分布式系统的调试不知道大家有什么好的方法.对于我来说,在知道远程调试这个方法之前就是在代码中打各种log,然后重新部署,上线,调试,这样比较费时.今天咱们来了解了解Java远程调试这个牛逼的 ...