October/Winter CMS的邮件系统

后端开发

OctoberCMS的邮件系统需要了解这几个重要信息:

  1. Drivers插件:https://octobercms.com/plugin/october-drivers,此插件的功能是提供Queue队列,Mail和Storage等服务
  2. 关于Mail的官方文档:https://docs.octobercms.com/2.x/services/mail.html
  3. 邮件队列:https://docs.octobercms.com/2.x/services/queues.html

准备邮件模板,本文以联系表单为例

后台 Settings > Mail templates > New template 然后按照下面设置

layout Default
code: contact::form
subject: Contact form submitted
description: Sent when a user submits the contact form.
最后是HTML模板

<p>From: {{ name }} <{{ email }}></p>
<p>Subject: {{ subject }}</p>
<p>Message Body:</p>
<p>{{ content }}</p>
<p>--</p>
<p>This mail is sent via contact form found on zhuli.fr!</p>

需要注意的是这里不能使用{{message}}做变量,会引起错误,官方解释是

$message variable is not available in markdown messages. 来源: https://laravel.com/docs/5.6/mail#writing-mailables

最后是邮件的发送

        $vars = ['name' => post('name'), 'email' => post('email'), 'content' => post('message'), 'message' => post('message')];
        
        Mail::send('contact::form', $vars, function($message) {
        
            $message->to('[email protected]', 'Julian');
            $message->subject(post('subject'));
        
        });      

邮件队列

Mail::queue('acme.blog::mail.welcome', $data, function ($message) {
    //
});

延时发送

Mail::later(5, 'acme.blog::mail.welcome', $data, function ($message) {
    });

SMTP服务器的配置

后台Mail configuration,文件config/mail.php

Post Comment