需要在Yii PHP中输入命令

jutyujz0  于 2022-11-09  发布在  PHP
关注(0)|答案(4)|浏览(117)

我正在使用Yii框架进行网页开发。
我试图使电子邮件cron作业,为此我使用PHPMailer。
这是我配置文件/控制台.php

> return array(
>     'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
>     'name'=>'My Console Application',
> 
>     // preloading 'log' component
>     'preload'=>array('log'),
>     'import'=>array(
>             'application.modules.*',
>             'application.extensions.*',
>             'application.components.*',
>             'application.models.*',
>         ), ....

我的命令/测试命令.php**

class UptimeCheckerCommand extends CConsoleCommand{
    public function run($args) { 
.... 
$warning->send(); 
....

组件/警告.php

....
require("/protected/extensions/PHPMailer/class.phpmailer.php");
....

错误报告:

PHP Error[2]: require(/protected/extensions/PHPMailer/class.phpmailer.php): fail
ed to open stream: No such file or directory

我已经用组件的控制器测试过了,它工作得很好。只有当我试图用yiic test命令访问它时,错误才会发生。
任何帮助都将不胜感激

daolsyd0

daolsyd01#

'import'=>array(
   ...
   'application.extensions.PHPMailer.*',
   ...
)

并将文件class.phpmailer.php重命名为PHPMailer.php
导入目录不会导入其任何子目录。

iyr7buue

iyr7buue2#

试试看:

$mailer = Yii::import('application.extensions.phpmailer');

然后使用**$mailer***发送电子邮件 *

igetnqfo

igetnqfo3#

Yii::import('application.extensions.phpmailer');

然后,您可以使用以下方法创建对象:

$mail = new PHPMailer();
lnlaulya

lnlaulya4#

感谢您的快速回复。
我已经试过上面一些建议了。

安德烈·沙季洛夫的建议不起作用。

对于usman allammazraara的建议进行修改:
“/protected/extensions/PHPMailer/class.phpmailer.php“(文件名:/保护的/扩展的/phpmailer/class. phpmailer. php)中指定的文件类型。

Yii::import('应用程序.扩展名. phpmailer.class. phpmailer.php');
我也不能工作,因为文件名中有点(class.phpmailer.php)
因为它,Yii认为我请求的是class文件夹中的phpmailer.php而不是class.phpmailer.php
有效的代码:

需要(“.../受保护/扩展/PHPMailer/class. phpmailer. php”);

我不知道为什么这个工作,因为我的testCommand.php在/protected/command/testCommand. php和我的phpmailer文件在/protected/extensions/PHPMailer/,但它的工作.

相关问题