Greetings!
I just downloaded version 2.0.1 of CodeIgniter framework and I am attempting to write my own email controller like so:
<?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()); }
}
}
If I point my browser to “http://localhost/CodeIgniter/index.php/email”, I get this PHP error message
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: config
Filename: controllers/email.php
Line Number: 24
The line number 24 points to this line of code in my controller $this->load->library(’email’, $config);
In spite of the PHP error, email is being sent fine, with a file attachment.
How can I remove this PHP error? What am I doing wrong?
As the message states, $config is not defined. You could fix it by defining it.
$config = Array();somewhere before line 24 should do it