Activation Email Could Not Send On User Registration

Hi I am new to Yii. I am working on a project in which currently I am working on user registration section.

I am facing this error.

Non-static method XHtml::sendHtmlEmail() should not be called statically, assuming $this from incompatible context

and my action is

public function actionRegister() {

    $model = new Members;


    $model->scenario = 'register';





    $this->performAjaxValidation($model);





    if (isset($_POST['Members'])) {


        $model->attributes = $_POST['Members'];





        if ($model->save()) {





            $activation_url = $this->createAbsoluteUrl('/site/activate', array('key' => $model->active_key, 'email' => $model->email));


            if (XHtml::sendHtmlEmail(


                            $model->email, Yii::app()->name . ' Administrator', null, Yii::t('register', 'Account activation'), array('username' => $model->user_name, 'activation_url' => $activation_url), 'activation', 'main2', null, null


                    )


            ) {


                $msg = Yii::t('register', 'Please check your email inbox for the activation link.It is valid for 24 hours.');


                Yii::app()->user->setFlash('success', $msg);


                $this->redirect(array('site/login'));


            } else {


                $model->delete();


                $msg = Yii::t('register', 'Error.Activation email could not be sent.Please register again.');


                Yii::app()->user->setFlash('error', $msg);


                $this->redirect(array('members/register'));


            }


            Yii::app()->user->setFlash('success', '<strong>Well done!</strong> You successfully registered with DPS and will notify you when we are live.');


            $this->redirect(array('site/thanks'));


        }


    }





    $this->render('register', array(


        'model' => $model,


    ));


}

Plz anyone help me in this regard. Thanks in advance.

Hi,

Please use code tag to paste your code… its very hard to read your code :(

Basically this means that the method XHtml::sendHtmlEmail is defined like ‘public’ instead of ‘public static’.

This can be caused by legacy code (the exception wasnt raised before php 5.x.x (5.2?)) or by incorrect usage.

You should see class docs (or the method itself) to determine how this method must be called.

If it’s actually static you can just change function signature from public function to public static function and everything will be ok.

If it’s an object method ($this is used in it) then you need to create class object instance to use the method: $mailer = new XHtml(…); $mailer->sendHtmlEmail(…);