sending mail in console controller

I’m trying to send mails using the swiftmailer in a console controller. I get no error, but the mails are not getting sent.

This is the controller:




<?php


namespace app\commands;


use yii\console\Controller;

use app\models\Booking;


/**

 * This command executes the daily cronjob

 *

 */

class CronjobController extends Controller

{

 

    public function actionIndex()

    {

        $starttime = date("Y-m-d 00:00:00", strtotime("tomorrow"));

        $endtime = date("Y-m-d 23:59:59", strtotime("tomorrow"));

        

        $bookings = Booking::find()->where(['between','datetime_start',$starttime,$endtime])->all();

        

        foreach ($bookings as $booking)

        {   

            echo "Sending email to " . $booking->user->email . "\n";

            

            \Yii::$app->mailer->compose('reminderbooking',[

                        'name' => $booking->user->fullNameNoComma,

                        'instrument' => $booking->instrument->name,

                        'datetime_start' => $booking->datetime_start,

                        'datetime_end' => $booking->datetime_end,

                        'hasVoltages' => !empty($booking->instrument->Voltages),

                        'staffEmail' => $booking->instrument->staff->email,

                    ])

             ->setFrom(\Yii::$app->params['adminEmail'])

             ->setTo($booking->user->email)

             ->setSubject('Booking reminder')

             ->send();

        }

    }

    

}



This is the config:




 'mailer' => [

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

            // send all mails to a file by default. You have to set

            // 'useFileTransport' to false and configure a transport

            // for the mailer to send real emails.

            'useFileTransport' => true,

	    /*'transport' => [

	       'class' => 'Swift_SmtpTransport',

	       'host' => 'xxxxx',

	       'username' => 'xxxx',

	       'password' => 'xxxx',

               'encryption' => 'tls',

	    ],*/

            'viewPath' => '@app/mail',

        ],



The controller returns the echo command, no error message is displayed, sending the mail returns true. I looked in the mail directory, nothing shows up. Using similar code in the website works. Where is the error here?

Set your useFileTransport to false.

The point is, if I want to have fileTransport to be true, it doesn’t save a text file. I dug into the code, apparently fileTransport is false when I send a message in the console controller, but not when I’m using it in a regular controller.