Issue
i am working on a cakephp 2.3. i want to load Email component into my class which is in Lib folder. same case for Vendor files too at the moment what i am doing is this..
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 = 'no-reply@hello.com';
$this->Email->to = $toEmail;
$this->Email->subject = $subject;
$this->Email->sendAs = 'both';
$this->Email->delivery = 'smtp';
$this->Email->send();
}
i am not able to use $this
.. i am getting this error
$this when not in object context
Solution
You don't do that, components are controller "extensions", they are not ment to be used without them.
For emailing purposes use the CakeEmail
class (the E-Mail component is deprecated anyways).
App::uses('CakeEmail', 'Network/Email');
// ...
$Email = new CakeEmail(array(
'port' => 25,
'timeout' => 30,
'host' => 'host',
'username' => 'username',
'password' => 'password',
'transport' => 'Smtp'
));
$Email->template($template)
->emailFormat('both')
->from('no-reply@hello.com')
->to($toEmail)
->subject($subject)
->send();
Answered By - ndm Answer Checked By - Timothy Miller (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.