R
R
Ruslan Dzh2019-05-16 07:02:59
Yii
Ruslan Dzh, 2019-05-16 07:02:59

How to set up sending an email about authorization in yii2 with a specific message text?

You need to configure email notification about user authorization.
Configured like this in main.php

'log' => [
    'traceLevel' => YII_DEBUG ? 3 : 0,
    'targets' => [
        [
            'class' => 'yii\log\FileTarget',
            'levels' => ['error', 'warning'],
        ],
        [
            'class' => 'yii\log\FileTarget', //в файл
            'categories' => ['payment_fail'], //категория логов
            'logFile' => '@runtime/logs/pay.log', //куда сохранять
            'logVars' => [] //не добавлять в лог глобальные переменные ($_SERVER, $_SESSION...)
        ],
        [
            'class' => 'yii\log\EmailTarget', //шлет на e-mail
            'categories' => ['payment_success'],
            'mailer' => 'yii\swiftmailer\Mailer',
            'logVars' => [],
            'message' => [
                'from' => ['[email protected]' => 'НАЗВАНИЕ САЙТА'], //от кого
                'to' => ['[email protected]'], //кому
                'subject' => 'Получен платеж. Лог в теле сообщения.', //тема
            ],
        ],
    ],
],

According to the example from the site
, everything works, but I would like the body of the letter to contain readable information like:
User : such and such
Was successfully authorized in the system at : date/time
But now only the following comes out:
2019-05-16 09:29:29 [::1][-][-][info][login_true] [
'status' => 'User is logged in',
'post' => [],
]

How can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
slip31, 2019-05-16
@rdzh

https://www.yiiframework.com/doc/guide/2.0/en/tuto...
Yii provides the ability to design the content of email messages through special view files. By default, these files should be located in the '@app/mail' directory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question