繁体   English   中英

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:

<?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中,这是main.php。 这将控制Web应用程序设置。 控制台也有一个配置文件-console.php。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM