Mailing API

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(‘[email protected]‘, ‘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(‘[email protected]‘, ‘Nova Framework‘);

        $message->to(‘[email protected]‘)->cc(‘[email protected]‘);

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

时间: 2024-10-10 23:54:03

Mailing API的相关文章

HTTP methods 与 RESTful API

目录: RESTful 是什么 JSON-server (提供 RESTful API 接口 + JSON 返回数据) 如何选择 REST 方法 HTTP verbs / method (安全 | 幂等) HTTP POST V.S. PUT REST POST | PUT | PATCH RESTful 是什么 阮一峰:理解RESTful架构 Representational State Transfer 表征状态转移 核心:resource.representation 指的是 resour

[转]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 word processing applications (Word, WordPerfect, and so on) provide the capability to create a “mail merge” from which to generate mailing labels in dif

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

转自:http://blog.csdn.net/jmq_0000/article/details/7536805#t136 Video for Linux Two API Specification Revision 0.24 Michael H Schimek <[email protected]> Bill Dirks Hans Verkuil Martin Rubli Copyright © 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,

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 Linux Two API Specification Revision 2.6.32 Michael H Schimek <[email protected]> Bill Dirks Original author of the V4L2 API and documentation. Hans

JavaMail API详解

版权声明:本文可以自由转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明 作者:cleverpig(作者的Blog:http://blog.matrix.org.cn/page/cleverpig)原文:http://www.matrix.org.cn/resource/article/44/44101_JavaMail.html关键字:java,mail,pop,smtp 一.JavaMail API简介JavaMail API是读取.撰写.发送电子信息的可选包.我们可用它来建立

WHM API 1 - createacct

WHM API 1 - createacct Skip to end of metadata Created by Sync User, last modified on Sep 29, 2014 Go to start of metadata Overview Parameters Examples Overview This page contains the input variables, output variables, and examples in JSON and XML ou

百度地图API实现批量地址解析

1.前言 写这篇文章的原因是最近做一个GIS项目在网上爬取了一些数据,无奈只有地址的文字信息没有坐标信息,如何把信息显现在地图上呢?很纠结啊,查看了一下百度地图API惊奇的发现百度提供了地址解析的API,然后查看了他的Demo后豁然开朗,所以动手将自己的文字信息数据进行解析坐标信息.下面开始讲解. 2.方案 (1)自己数据库中的数据 (2)百度地图API Demo <!DOCTYPE html> <html> <head> <meta http-equiv=&qu

【API】高德地图API JS实现获取坐标和回显点标记

1.搜索+选择+获取经纬度和详细地址 2.回显数据并点标记 3.实现 第一步:引入资源文件 <!--引入高德地图JSAPI --><script src="//webapi.amap.com/maps?v=1.3&key=在官网申请一个key"></script><!--引入UI组件库(1.0版本) --><script src="//webapi.amap.com/ui/1.0/main.js">

【Windows10&nbsp;IoT开发系列】API&nbsp;移植工具

原文:[Windows10 IoT开发系列]API 移植工具 Windows 10 IoT Core 中是否提供你的当前 Win32 应用程序或库所依赖的 API? 如果不提供,是否存在可使用的等效 API? 此工具可以为你回答这些问题,并协助你将你的当前 Win32 应用程序和库迁移到 Windows IoT Core. Windows 10 IoT 核心版 API 移植工具可在 ms-iot/iot-utilities github 存储库中找到.下载存储库 zip 并将 IoTAPIPor