Hi All
I am trying to send emails via a cron using yii
Can someone please help me with this error
exception ‘CException’ with message ‘Property “CConsoleApplication.mail” is not defined.’ in …\framework\base\CComponent.php:174 Stack trace:
#0 …\framework\base\CModule.php(483): CComponent->__set(‘mail’, Array)
#1 …\framework\base\CApplication.php(144): CModule->configure(Array)
#2 …\framework\YiiBase.php(127): CApplication->__construct(‘file location…’)
#3 …\framework\YiiBase.php(115): YiiBase::createApplication(‘CConsoleApplica…’, ‘file location…’)
#4 …\console.php(13): YiiBase::createConsoleApplication(‘file location…’)
#5 {main}
Console.php
$yii=dirname(__FILE__).'/../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/Config.php';
defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
require_once($yii);
Yii::createConsoleApplication($config)->run();
Config.php
'mail' => array(
'class' => 'ext.mail.YiiMail',
'transportType' => 'smtp',
'transportOptions'=>array(
'host'=>'smtp.gmail.com',
'encryption'=>'ssl', // use ssl
'username'=>'username@gmail.com',
'password'=>'password',
'port'=>465, // ssl port for gmail
),
'viewPath' => 'application.views.mail',
'logging' => true,
'dryRun' => false
),
dairyemailsendCommand.php
class DairyemailsenderCommand extends CConsoleCommand{
public function getHelp() {
echo "Checks dairy and sends emails when dairy items are due.";
}
public function run($args) {
$name = date('M')."_dairy_emails_{$d['user']}";
Yii::import('ext.yii-mail.YiiMailMessage');
$message = new YiiMailMessage;
$message->setBody('test', 'text/html');
$message->addTo('toemailaddress');
$message->from = Yii::app()->params['adminEmail'];
Yii::app()->mail->send($message);
}
}