我正在尝试使用shell发送电子邮件。但是,我无法将变量正确传递到我的电子邮件模板中。我已经查看了多个网站寻求帮助,但似乎没有任何效果。
我已经尝试过(如此处所示)只传递一个字符串,即使这样也无效。
class AbandonedEmailShell extends Shell {
var $uses = array('AbandonedCart');
function main() {
App::import('Core', 'Controller');
App::import('Component', 'Email');
$this->Controller = & new Controller();
$this->Email = & new EmailComponent(null);
$this->Email->initialize($this->Controller);
$this->Controller->ext = '.php';
$abcarts = $this->AbandonedCart->find('all', array(
'conditions' => array(
'created >' => date('Y-m-d H:i:s', strtotime('-2 day')),
'email_sent =' => 0
)
));
//THIS IS A LOOP AS EVENTUALLY I WILL BE DOING MULTIPLE EMAILS
foreach($abcarts as $abcart){
//EMAIL
$this->Controller->set('data', 'hello');
$this->out($this->Controller->data);
$this->Email->to = 'me@me.com';
$this->Email->subject = 'test shell email';
$this->Email->template = 'abandoned_email';
$this->Email->sendAs = 'html';
$this->Email->send();
$this->Email->reset();
}
}
}
在我的abandoned_email模板中:
Hello,
<?php echo $data ?>
奇怪的是,即使我尝试使用$ this-&gt; out($ this-&gt; Controller-&gt; data)输出,我也没有得到任何东西。