PHP code example of zangsilu / yii2-mailer-queue

1. Go to this page and download the library: Download zangsilu/yii2-mailer-queue library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zangsilu / yii2-mailer-queue example snippets



'components'   => [
        'redis' => [
            'class' => 'yii\redis\Connection',
            'hostname' => '127.0.0.1',
            'port' => 6379,
            'database' => 0,
        ],
        /* 邮件发送设置 */
        'mailer'       => [
            'class'            => 'zangsilu\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',
            ],
        ],
    ];



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 '发送完毕!';
    }

}