send email with link

Viewed 354

This code outputs:

Call to a member function link() on a non-object 

What I want is send a link in email. What is wrong with the code? thanks

class User extends AppModel {
    public $helpers = array('Html');
    public function sendEmail($email_user, $code) {
            $email = new CakeEmail();
            $email->config('smtp');

            $pwrurl = "http://xxx/users?se=check&mail=".$email_user."&code=".$code;
            $link = $this->Html->link('Link name', $pwrurl, array('target' => '_blank'));
            $email->from(array('xxxn@gmail.com' => 'xxxx'))
            ->to($email_user)
            ->emailFormat('html')
            ->send('My message:: '.$link);
            return true;
        }
}

docs

Update: I get the same error.

App::uses('CakeEmail', 'Network/Email');
App::uses('AppHelper', 'View/Helper');

class AppController extends Controller {
      public $helpers = array('Form', 'Html');

      public function sendEmail($email_user, $codeLink) {
             //same code.
      }

}

3 Answers
Related