• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED ]Undefined variable: config -- PHP error but email is sent.


I am a *newbie* and just downloaded CI version 2.0.1. Please bear with me with this long email.

I am attempting to write my own email controller like so:


class Email extends CI_Controller
     function __construct()     {         parent::__construct();     }
    function index()     {  
        $this->load->library('email', $config);
        $this->email->from('[email protected]', 'some.email.name');
        $this->email->to('[email protected]');        
        $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';
        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

Quote: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
Quote:$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?


I added $config = Array(); in my index() function. The error went away.

Stupid, stupid, stupid me.

[eluser]Eric Barnes[/eluser]
That is because you are not setting $config. So change your line to: $this->load->library('email');

Change $this->load->library('email', $config); to $this->load->library('email'); unless you actually need to change the default config in which case you'd do something like this:-


$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";

$this->email->from('[email protected]', 'some.email.name');
$this->email->to('[email protected]');        
$this->email->subject('This is an email test');        
$this->email->message('It is working!');


[quote author="Eric Barnes" date="1302052414"]That is because you are not setting $config. So change your line to: $this->load->library('email');[/quote]

I did what you suggested. Problem went way (makes sense).

Thanks for the reply.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.