使用CakeResque将电子邮件发送为后台进程

时间:2013-10-01 09:34:55

标签: php email backgroundworker background-process cakephp-2.4

MailShell.php

<?php

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

class MailShell extends AppShell
{

    public function sendMail() {
        $Email = new CakeEmail();
        $Email->from(array('admin@localhost' => 'My Site'));
        $Email->to($this->args[1]);
        $Email->subject($this->args[3]);
        $Email->send($this->args[2]);
    }
}

TestController.php

<?php
App::uses('AppController', 'Controller');

class TestController extends AppController {

    public function index(){
        CakeResque::enqueue('default','CakeResque.Mail', array('sendMail','test@gmail.com','Test Email','Hi this it test email.'));
    }
}

当我打开网址时

http://localhost/test/index

作业在默认队列中正确排队,请参阅

enter image description here

当我开始工作时,以及统计数据如下所示

enter image description here

对于每个作业它增加已处理的作业1 失败的作业2 并且电子邮件不会发送

什么是真正的问题?电子邮件发送程序有问题吗? CakeResque有问题吗?

任何帮助表示赞赏

谢谢

1 个答案:

答案 0 :(得分:0)

从TestController中排队作业时使用

CakeResque::enqueue('default',
                    'CakeResque.MailShell',   //difference is here
                     array('sendMail',
                           'test@gmail.com',
                           'Test Email',
                           'Hi this it test email.'));

而不是

CakeResque::enqueue('default',
                    'CakeResque.Mail',                                   
                     array('sendMail',
                          'test@gmail.com',
                          'Test Email',
                          'Hi this it test email.'));