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.

最新文章

  1. 【JUC】JDK1.8源码分析之AbstractQueuedSynchronizer(二)
  2. TCP与UDP的区别
  3. Python开发【杂货铺】:模块logging
  4. Duilib嵌入CEF以及JavaScript与C++交互
  5. Redis常用命令入门2:散列类型
  6. Java多线程(转)
  7. 开窗函数 --over()
  8. Android组件Spinner使用
  9. 昂贵的聘礼 Dijkstra法
  10. 0_Linux_虚拟机安装
  11. PHP - 验证用户名
  12. June本地环境搭建
  13. Spring整合Shiro并扩展使用EL表达式
  14. 003-单例OR工厂模式
  15. react项目中页面跳转、刷新及获取网络状态
  16. 工控安全入门之Ethernet/IP
  17. Redhat5_linux 系统环境下 oracl11g的安装教程图解
  18. delphi如何检索adoquery里面某一列存在的重复行?
  19. 【LeetCode】40. Combination Sum II (2 solutions)
  20. JavaScript基础细讲

热门文章

  1. POJ 1258 Agri-Net
  2. Live555研究之二Sleep实现
  3. Zabbix探索:模板中发现规则的使用
  4. VirtualBox故障一例
  5. 无状态、REST、RESTful 和 Web Services【整理】
  6. 如何实现CSS居中?–CSS居中常用方法
  7. Java中万恶的注解
  8. work2
  9. DTD - Elements
  10. 第二十章、启动流程、模块管理与 Loader