Yii 2: unable to mail log

This is my post component. As you can see, due to my testing purposes, I am using email in the file

'mailer' => [
        'class'             => 'yii\swiftmailer\Mailer',
        'viewPath'          => '@common/mail',
        'useFileTransport'  => true,
    ],

      

This is my log component.

'log'       => [
        'traceLevel' => YII_DEBUG ? 3 : 0,
        'targets'   => [
            [
                // for this target, see http://www.yiiframework.com/doc-2.0/guide-runtime-logging.html
                'class'         => 'yii\log\EmailTarget',
                'levels'        => ['error'],
                'categories'    => ['yii\db\*', 'email_test'],
                'message'       => [
                   'from'           => ESHOP_EMAIL,
                   'to'             => DEVELOPER_EMAIL,
                   'subject'        => 'Errore db [' . YII_ENV . ']',
                ],
            ],
        ],
    ],

      

In siteControlle-> actionIndex () I am testing the log and email component this way

public function actionIndex()
{
    Yii::error("testing mail log", "email_test");

    Yii::$app->mailer->compose()
        ->setFrom([ESHOP_EMAIL => ESHOP])
        ->setTo( DEVELOPER_EMAIL)
        ->setSubject("actionIndex executed on time " . date ("H:i:s"))
        ->setTextBody("Useless body")
        ->send();

    return $this->render('index');
}

      

As I expected, on every reload of the index page, I got 2 .eml

files created inside the folder frontend/runtime/mail

.

So SwiftMailer works and even the log system.

Now the problem

I am trying to remove file usage from a component mailer

by commenting out the line

        'useFileTransport'  => true,

      

When I reload the index page, I got a SECOND MAIL, one that was manually compiled and sent, but I WILL NOT RECEIVE the first mail, which should be automatically compiled and submitted by the registration system using SwiftMailer.

What's wrong?

+3


source to share


3 answers


Sorry for everyone.



The problem was a mistake in the destination address. With the registrar, the error caused by the email cannot be sent, but with the manual sending of the address error to the addressee, it is simply ignored and the email is sent.

+1


source


I think the default for 'useFileTransport' is true

. Better to install false

and not comment on it



+1


source


If you are not using php function to send email you need a transport like this

 'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@common/mail',
        //'useFileTransport' => true,
        'useFileTransport' => false, //set this property to false to send mails to real email addresses
        //comment the following array to send mail using php mail function
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.gmail.com',
            'username' => 'your_mail@gmail.com',
            'password' => 'your_password',
            'port' => '587',
            'encryption' => 'tls',
        ],

      

And if you are not using gmail, you need to configure the parameter correctly.

0


source







All Articles