Php 使用CakeResque作为后台进程发送电子邮件
MailShell.phpPhp 使用CakeResque作为后台进程发送电子邮件,php,email,backgroundworker,background-process,cakephp-2.4,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@lo
<?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]);
}
}
<?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.'));
}
}
作业在默认队列中正确排队请参见
当我开始工作后,统计数据如下所示
对于每个作业,它将处理的作业增加1,失败的作业增加2,并且不发送电子邮件
什么是真正的问题?电子邮件发送程序有问题吗?卡克尔式有问题吗
谢谢你的帮助
感谢您在使用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.'));
TestController不必找到MailShell,因为它从不使用它。问题在于排队时引用作业类的方式,请使用
CakeResque.MailShell
而不是CakeResque.Mail
在CakeResque::enqueue
@Kamisama中引用队列时,感谢您的回复,代码现在正在工作,但仍然不知道为什么它会增加失败的作业,尽管作业已成功进行,并且您的教程很好。您应该在github上打开一个票证,并提供重现该问题所需的一切
CakeResque::enqueue('default',
'CakeResque.Mail',
array('sendMail',
'test@gmail.com',
'Test Email',
'Hi this it test email.'));