Yii:控制台 cron 应用程序不发送电子邮件


Yii: console cron application is not sending email

我的控制台 cron 应用程序没有发送电子邮件。邮件发送与网络应用程序完美配合使用。我应该配置一些选项还是你能给我正确的方向?

受保护/cron.php:

<?php
 require_once(dirname(__FILE__) . '/../components/helpers.php');
 return array(
'basePath'   => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
'name'       => 'Cron',
'preload'    => array('log'),
'import'     => array(
    'application.models.*',
    'application.components.*',
),
'components' => array(
    'cache'        => array(
        'class' => 'system.caching.CFileCache'
    ),
    'mail'         => array(
        'class'         => 'ext.yii-mail.YiiMail',
        'transportType' => 'php',
        'viewPath'      => 'application.views.mail',
        'logging'       => false,
        'dryRun'        => false,
    ),        
),
'params'     => array(
    'adminEmail' => 'some_email@he.re',
),

);

以及我的模型上的电子邮件发送方法:

public function sendEmail()
    {
        if ($this->mail) {
            if ($this->user->email) {
                try {
                    $notification = $this->notification;
                    Yii::import('ext.yii-mail.YiiMailMessage');
                    $params           = array('notification' => $notification);
                    $message          = new YiiMailMessage;
                    $message->view    = "notification";
                    $message->subject = __('MyApp: title', array(':title' => $notification->title));
                    $message->from    = Yii::app()->params['adminEmail'];
                    $message->setBody("dasdasd");
                    $message->setTo($this->user->email);
                    if (Yii::app()->mail->send($message) > 0) {
                        $cmd = Yii::app()->db->createCommand();
                        $cmd->update($this->tableName(), array('mail' => 1), "id={$this->id}");
                        print_r($this->getAttributes());
                    }
                } catch (Exception $e) {
                    Yii::log($e->getMessage(), CLogger::LEVEL_ERROR);
                }
            }
        }
    }

cron.php 在 web-root 上:

<?php
defined('YII_DEBUG') or define('YII_DEBUG',true);
require_once('../yii/framework/yii.php');
$configFile='protected/config/cron.php';
Yii::createConsoleApplication($configFile)->run();

您还必须在控制台配置文件中配置邮件组件。控制台和 Web 视图有自己的配置文件。在 Yii 版本 1.1.xx 中,这是主要的.php。这将控制 Web 应用程序设置。控制台还有一个配置文件 - console.php。