哈哈,前進 - in CakePHP 2.0 - 電子郵件類將是一流的公民,而不是一個組成部分。因此,我不會擔心通過發送來自(god-forbid)模型或shell或其他有用的地方的電子郵件來激怒MVC神。
你必須通過一些箍雖然跳:
// we will need a controller, so lets make one:
App::import('Core', 'Controller');
$controller =& new Controller();
// lets grab the email component
App::import('Component', 'Email');
$email =& new EmailComponent();
// give it the reference to the controller
$email->initialize($controller);
// off we go...
$email->from = 'Name <[email protected]>';
$email->replyTo = '[email protected]';
$email->sendAs = $format;
$email->to = $destination;
$email->subject = $subject;
// oh, this is why we needed the controller
$email->template = $template;
$controller->set(compact('items', 'subject'));
// done.
$sent = $email->send();
CakePHP的2.0s的電子郵件類,可以從任何地方發送電子郵件 – Dunhamzzz