CakePHP using Email component from Shell cronjob

前端 未结 4 1407
萌比男神i
萌比男神i 2021-01-02 01:19

I\'m trying to send an email from a CakePHP shell just as you would from the Controller.

Most of the code below was adapted from this dated article on the Bakery an

4条回答
  •  庸人自扰
    2021-01-02 01:34

    If you're using CakePHP 2.x, you can ditch the EmailComponent entirely and use the CakeEmail class instead.

    App::uses('CakeEmail', 'Network/Email');
    
    class NotificationShell extends Shell {
        public function send() {
            $email = new CakeEmail();
        }
    }
    

    That entirely avoids all the thorny issues of loading components inside a shell. For email at least.

提交回复
热议问题