Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cakephp how to import CakeEmail into Shell

I'm on Cakephp 2.4.5, How do i make use of / import CakeEmail functions so i can use them in my Shell script? I've searched everywhere but can't find an answer. Most examples talk about sending an email from a Controller but not a Shell.

This Shell is executed by a Cron job.

I've tried the following:

class EmailShell extends AppShell {

    //App::uses('CakeEmail', 'Network/Email'); ///Results in Error: Parse error: syntax error, unexpected 'App' (T_STRING),
    //App::import('Component', 'Email');  //Results in Error: Parse error: syntax error, unexpected 'App' (T_STRING),
    $tasks = array('Email'); //Results in Error: [0m Task class EmailTask could not be found.

    public function main () {
             //email sending logic here
    }
like image 928
aDvo Avatar asked May 29 '26 06:05

aDvo


1 Answers

App::uses statements need to be above the class start:

App::uses('CakeEmail', 'Network/Email');

class EmailShell ...

Then you can use it anywhere in this file class:

$Email = new CakeEmail();
...
like image 104
mark Avatar answered Jun 01 '26 22:06

mark