Welcome Guest, Not a member yet? Register   Sign In
Undefined Variable: Config
#1

[eluser]Watermark Studios[/eluser]
Okay, so I am running through the video tutorials in the Wiki and I am finishing up the email tutorial.

This is the error I'm getting right now:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: config

Filename: controllers/email.php

Line Number: 12

I moved my configuration information to a file called email.php in the config folder. That file looks like:

Code:
<?php    if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$config['protocol'] = 'sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = '**********';
$config['smtp_pass'] = '**********';

Keep in mind that I have to use the sendmail protocol because HostMonster doesn't support the smtp protocol. When I had the $config array defined in my email.php controller, everything worked fine. Now that I have the $config array defined in a config folder file it still works, but I get the error at the top of the page.

Below is my code from my email.php in the controller folder:

Code:
<?php

class Email extends Controller
{
    function __construct()
    {
        parent::Controller();
    }

    function index()
    {
        $this->load->library('email', $config);
        $this->email->set_newline("\r\n");
        
        $this->email->from('********@gmail.com', 'Ken Anderson');
        $this->email->to('********@gmail.com');
        $this->email->subject('This is an e-mail test');
        $this->email->message('Its working');
        
        $path = $this->config->item('server_root');
        $file = $path . '/codeigniter/attachments/yourinfo.txt';
                
        $this->email->attach($file);
        
        if($this->email->send())
        {
            echo 'Your email was sent, fool';        
        }
        else
        {
            show_error($this->email->print_debugger());    
        }
    }

}

Attached is a JPG of my filesystem setup.

I understand that technically $config is not defined in the controller, but it is through the email.php file in the config folder.

Please help

Ken
#2

[eluser]n0xie[/eluser]
When setting up a email config file you do not need to load it manually:
Quote:http://ellislab.com/codeigniter/user-gui...email.html
Setting Email Preferences in a Config File

If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the email.php, add the $config array in that file. Then save the file at config/email.php and it will be used automatically. You will NOT need to use the $this->email->initialize() function if you save your preferences in a config file.

This should work just fine:
Code:
$this->load->library('email');
#3

[eluser]Watermark Studios[/eluser]
I was passing the $config array in the load statement:

Code:
$this->load->library('email', $config);

But $config isn't defined until email is loaded.

I changed it to:

Code:
$this->load->library('email');

and it worked just fine.

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB