Chinmay Waghmare
Chinmay Waghmare

Reputation: 5456

How do I run Console application function from frontend?

I want to run the Console application send mail function from the frontend. I tried using this extension but it isn't working.

namespace console\controllers;

use Yii;

/**
 * Console controller
 */
class ConsoleController extends  \yii\console\Controller
{
   public function actionSendMail()
   {
        Yii::$app->mailer->compose()
                ->setFrom('[email protected]')
                ->setTo('[email protected]')
                ->setSubject('Message subject')
                ->setTextBody('Plain text content')
                ->setHtmlBody('<b>HTML content</b>')
                ->send();
   }
}

From command line I can use yii console/send-mail and it works fine.

But how can I run the above command in frontend controller?

Upvotes: 1

Views: 1269

Answers (1)

vitalik_74
vitalik_74

Reputation: 4611

Don't work, because https://github.com/vova07/yii2-console-runner-extension/blob/master/ConsoleRunner.php#L63 PHP_BINDIR in my computer value 'C\php'. But in my computer PHP not install in 'C\php' directory. You may:

1) Create 'C\php' folder and put php.exe into this directory.

2) Or add PHP_BINDIR variable in Environment variables (how that - http://www.itechtalk.com/thread3595.html) and put in your correct path to php.exe. And restart computer.

In my computer I run first step and run Yii::$app->consoleRunner->run('hello/some-action') in SiteControler and it is work fine.

Upvotes: 1

Related Questions