我正在cakephp 2.3上工作。我想將電子郵件組件加載到我的Lib文件夾中的類中。對於供應商相同的情況下,在那一刻文件了我在做什麼是這個..如何在Lib或Vendor文件中加載組件
App::uses('EmailComponent', 'Controller/Component');
class Email {
public static function sendemail($toEmail,$template,$subject) {
$this->Email->smtpOptions = array(
'port'=>'25',
'timeout'=>'30',
'host' => 'host',
'username'=>'username',
'password'=>'password'
);
$this->Email->template = $template;
$this->Email->from = '[email protected]';
$this->Email->to = $toEmail;
$this->Email->subject = $subject;
$this->Email->sendAs = 'both';
$this->Email->delivery = 'smtp';
$this->Email->send();
}
我不能夠使用$this
..我得到這個錯誤
$這個時候不是在對象上下文
thaknyou ..我在我的Lib文件夾中的類中使用這個嗎? – hellosheikh
@hellosheikh您可以在任何需要的地方使用CakeEmail類,所以可以在庫中使用它。 – ndm
thankyouuuuuu它的工作原理 – hellosheikh