GithubHelp home page GithubHelp logo

yii2-mailer-queue's Introduction

yii2-mailer-queue

使用队列异步发送邮件v1.0.0

环境

  • PHP >= 5.4
  • yiisoft/yii2-redis >= 2.0.0
  • composer

安装

composer require shijiaoliang/yii2-mailer-queue

使用

  • 1:配置文件配置
<?php
'components'   => [
        'redis' => [
            'class' => 'yii\redis\Connection',
            'hostname' => '127.0.0.1',
            'port' => 6379,
            'database' => 0,
        ],
        /* 邮件发送设置 */
        'mailer'       => [
            'class'            => 'shijiaoliang\mailerqueue\MailerQueue',
            'redisDB'=>1,//使用redis1号库存储邮件队列
            'useFileTransport' => false, //必须改为false,true只是生成邮件在runtime文件夹下,不发邮件
            'transport'        => [
                'class'      => 'Swift_SmtpTransport',
                'host'       => 'smtp.163.com',
                'username'   => '',
                'password'   => '',
                'port'       => '465',//端口25对应tls协议 端口465对应ssl协议
                'encryption' => 'ssl',
            ],
        ],
    ];
  • 2:创建控制台指令
<?php

namespace app\commands;


use Yii;
use yii\console\Controller;

class MailerQueueController extends Controller
{

    /**
     * 发送redis队列中的邮件
     * php yii mailer-queue/send
     */
    public function actionSend()
    {
        $mailer = Yii::$app->mailer;
        $mailer->process();
        echo '发送完毕!';
    }

}
  • 3:将指令加入lunux定时任务(每分钟检测一次)
crontab -e
*/1 * * * * php yii mailer-queue/send > ./log/mailer-send.log

yii2-mailer-queue's People

Contributors

shijiaoliang avatar zangsilu avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.