• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in my email code

#1
[eluser]gibbo1715[/eluser]
HI all

My first post here, introduced to codeigniter yesterday and i love it!!!

can anyone spot my error in the code below please

Im trying to sort an email script on my local server through google mail following jeffrey Way's video tutorial but still getting an error

If i run an array on the controller page it works fine but if i try and have an email config file i get the error Undefined variable: config

My code is as follows

config/email.php

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

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'my password';


And my controller/email.php as follows

Code:
<?php

/**
* SENDS EMAIL WITH GMAIL
*/
class Email extends Controller
{
    function __construct()
    {
        parent::Controller();
    }
    
    function index()
    {    
    
    //$config = array(
  //  'protocol' => 'smtp',
  //  'smtp_host' => 'ssl://smtp.googlemail.com',
  //  'smtp_port' => 465,
  //  'smtp_user' => '[email protected]',
  //  'smtp_pass' => 'mypassword'
  //);
    
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
        
    $this->email->from('[email protected]', 'Paul Gibson');
    $this->email->to('[email protected]');        
    $this->email->subject('This is an email test');        
    $this->email->message('It is working. Great!');
        
    // look in config file to get config item
    $path = $this->config->item('server_root');
    $file = $path . '/d/lesson3/attachments/yourInfo.txt';
        
    //added an email.php file to the config folder
    $this->email->attach($file);
        
    if($this->email->send())
        {
            echo 'Your email was sent.';
        }
        
    else
        {
            show_error($this->email->print_debugger());
        }
    }
}

Thanks for looking and any help you can offer

Gibbo

#2
[eluser]gibbo1715[/eluser]
All

I have found if i put $config = ''; at the start of my function (see below) it works for me, this seems a bit weird to me to have to define my config as nothing to remove the error so if anyone has any other ideas as to whats going on let me know

thanks

gibbo

Code:
function index()
    {    
    
    $config = '';
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");

#3
[eluser]überfuzz[/eluser]
Welcome to the forum.

It's actually not so wierd that you have to define a variable before you use it. Question is, what you need it for if you set it to a blank string..?

[quote author="gibbo1715" date="1260041076"]...
Code:
function index()
    {    
    
    $config = '';
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
[/quote]

#4
[eluser]gibbo1715[/eluser]
Thanks for the reply, having walked away and considered this it occured to me where my error might be

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

i removed the $config and all errors gone as its declared in the email.php anyway

opps

thanks for looking

Gibbo


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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