YiiMailMessage and its behaviors do not have a method

Help solve the problem with the message:

Exception:YiiMailMessage and its behaviors do not have a method or closure named "setSubject"

and

Exception:YiiMailMessage and its behaviors do not have a method or closure named "setTo"

and

Exception:YiiMailMessage and its behaviors do not have a method or closure named "setFrom"

In protected/main/config.php:


'import'=>array(

         ...

        'application.extensions.yii-mail.*',

	),

...

'components'=>array(

    ...

    'mail' => array(

        'class' => 'application.extensions.yii-mail.YiiMail',

        'transportType'=>'smtp', /// case sensitive!

        'transportOptions'=>array(

            'host'=>'smtp.gmail.com',

            'username'=>'yourgoogleemail@gmail.com',

            // or email@googleappsdomain.com

            'password'=>'yourgooglemailpassword',

            'port'=>'465',

            'encryption'=>'ssl',

            ),

        'viewPath' => 'application.views.mail',

        'logging' => true,

        'dryRun' => false

    ),



In controller:




$message = new YiiMailMessage;

 

//userModel is passed to the view

$message->setBody('My text');

  

$message->setTo(array($userModel->email=>'My name'));

$message->from = Yii::app()->params['adminEmail'];

Yii::app()->mail->send($message);



The result of the action:




    Exception:YiiMailMessage and its behaviors do not have a method or closure named "setSubject"

    Exception:YiiMailMessage and its behaviors do not have a method or closure named "setTo"

    Exception:YiiMailMessage and its behaviors do not have a method or closure named "setFrom"



I had a similar problem!

Try and look for any classes/files in your yii app that have the same name as this class. I accidentally made a copy of a class a while ago which had the class prices in it. The original file had the class Prices in it. Somewhere in my app i still had a reference to different upper and lowercase versions of the prices class. That happened because i developed on a windows machine and the live machine was linux (they treat filenames/loading differently).

Hope this helps!

i had similar error too but it solved now!! thanks mateā€¦cheers!!