天天看點

yii2錯誤日志發送郵件

'components' => [

        'mailer' => [

            'class' => 'yii\swiftmailer\Mailer',

            'useFileTransport' => false, // 這句一定有,false發送郵件,true隻是生成郵件在runtime檔案夾下,不發郵件

            'transport' => [

                'class' => 'Swift_SmtpTransport',

                'host' => 'smtp.qq.com', // 每種郵箱的host配置不一樣

                'username' => '[email protected]',

                'password' => 'yzzuvvntfdwocihe', // 注意這裡不是郵箱登入密碼,而是QQ郵箱背景開啟STMP服務後給的授權碼

                'port' => '587', // 将發送伺服器的端口号修改成465或587,163郵箱25;

                'encryption' => 'tls'

            ],

            'messageConfig' => [

                'charset' => 'UTF-8',

                'from' => [

                    '[email protected]' => 'some'

                ]

            ]

        ],

    'log' => [

           'traceLevel' => YII_DEBUG ? 3 : 0,

            'targets' => [

                [

                    'class' => 'yii\log\DbTarget',

                    'levels' => ['error', 'warning'],

                ],

                [

                    'class' => 'yii\log\FileTarget',

                    'levels' => ['error', 'warning'],

                ],

                [

                    'class' => 'yii\log\EmailTarget',

                    'levels' => ['error'],

                    'categories' => ['yii\db\*'],

                    'message' => [

//                         'from' => ['[email protected]'],

                        'to' => ['[email protected]','[email protected]'],

                        'subject' => 'Database errors at example.com',

                    ],

                ],

            ],

        ],

],

轉載于:https://my.oschina.net/shuibing/blog/893191

繼續閱讀