【发布时间】:2011-07-30 06:53:30
【问题描述】:
您好!
我刚刚下载了 CodeIgniter 框架的 2.0.1 版,我正在尝试编写自己的电子邮件控制器,如下所示:
<?php
class Email extends CI_Controller
{
function __construct() { parent::__construct(); }
function index() {
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('some.email@gmail.com', 'some.email.name');
$this->email->to('some.author.email.@gmail.com');
$this->email->subject('This is an email test');
$this->email->message('It is working!');
$path = $this->config->item('server_root');
$file = $path . '/attachments/readme.txt';
$this->email->attach($file);
if($this->email->send()) { echo 'Email sent.'; }
else { show_error($this->email->print_debugger()); }
}
}
如果我将浏览器指向“http://localhost/CodeIgniter/index.php/email”,我会收到此 PHP 错误消息
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: config
Filename: controllers/email.php
Line Number: 24
第 24 行指向我的控制器中的这一行代码 $this->load->library('email', $config);
尽管出现 PHP 错误,但电子邮件发送正常,带有文件附件。
如何消除这个 PHP 错误?我做错了什么?
【问题讨论】:
-
通知只是一个信息性的“嘿,这是您可能想在某个时候查看的内容”。这不是错误或“有人给我们设置了炸弹!”。它们可以被忽略,但应该为了“完全”正确而处理。
标签: php codeigniter