Yii2 CLI SwiftMailer using sendmail instead of mail()

When running in CLI by crontab i get the following error:

"sh: sendmail: command not found"

When i run in SSH the same commando it just works. So i tryed forcing "Swift_MailTransport" by doing this before my code starts:




        \Yii::$app->setComponents([

            'mailer' => [

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

                'enableSwiftMailerLogging' => true,

                'useFileTransport' => false,

                'transport' => [

                    'class' => 'Swift_MailTransport',

                ]

            ],

        ]);



And the code (simple)




    public function actionTest()

    {

        \Yii::$app->mailer->compose()

            ->setFrom('test2@example.com')

            ->setTo('test1@example.com')

            ->setSubject('Message subject')

            ->setTextBody('Plain text content')

            ->setHtmlBody('<b>HTML content</b>')

            ->send();

    }



Does anyone know what i am doing wrong?

If some one else has this problem, it’s is because of the configuration of PHP. The Config file stated that it was using sendmail command for the php function mail(). We didnt found it because we had 2 configuration files, one for PHP 5.6 and one for PHP 7.0.