Welcome Guest, Not a member yet? Register   Sign In
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


Messages In This Thread
Error in my email code - by El Forum - 12-05-2009, 06:13 AM
Error in my email code - by El Forum - 12-05-2009, 07:24 AM
Error in my email code - by El Forum - 12-05-2009, 09:50 AM
Error in my email code - by El Forum - 12-05-2009, 09:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB