Welcome Guest, Not a member yet? Register   Sign In
Email library show me Fatal error: Call to a member function. [solved]
#1

[eluser]Ivan A. Zenteno[/eluser]
Hi to all.
I'm trying do Contact module, this is my class contact:

Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
class contact extends Controller{
    
    function __construct()
    {
        parent::Controller();
        $this->load->module("customers");
        $this->lang->load('message_static', 'spanish');
        $this->load->library('validation');
        $this->data = $this->settings_model->get_conf(array('class'=>'core'));
        $this->data['links'] = $this->customers->menu_links();
        $this->data['categories_list'] = $this->settings_model->get_all_categories();
    }
  
    function index()
    {
        $this->lang->load('message_static', 'spanish');
        $rules = array(
            'name' => 'trim|required|xss_clean|htmlspecialchars',
            'email' => 'trim|required|valid_email|xss_clean|htmlspecialchars',
            'message' => 'trim|required|xss_clean|htmlspecialchars');
        $this->validation->set_rules($rules);
        
        $fields = array(
            'name' => lang('msg_label_name'),
            'email' => lang('msg_label_email'),
            'message' => lang('msg_label_message') );
        $this->validation->set_fields($fields);
        $this->validation->set_error_delimiters('<div class="error">', '</div>');
        if($this->validation->run() == FALSE)
        {
            $this->template->write_view('header', 'common/header', $this->data, TRUE);
            $this->template->write_view('footer', 'common/footer');
            $this->template->write_view('categories', 'categories/category_list_view', $this->data);
            $this->template->write_view('login', 'customers/login_view');
            $this->template->write_view('content', 'contact_view', $data, TRUE);
            $this->template->render();
        }
        else
        {
            $message = $this->input->post('name')." \n". $this->input->post('message');
            $this->_email_send($this->input->post('email'), $message);
        }
    }
    
    function _email_send($email, $message, $subject = "Comment of Contact form" )
    {
        $this->data = $this->settings_model->get_conf(array('class'=>'core'));
        if($this->data['smtp_enable'] == TRUE)
        {
            $config = array(
                'protocol'  => 'smtp',
                'smtp_host' => $this->data['smtp_host'],
                'smtp_port' => $this->data['smtp_port'],
                'smtp_user' => $this->data['smtp_user'],
                'smtp_pass' => $this->data['smtp_password'],
                'word_wrap' => TRUE,
                'mailtype'  => 'text',
                'charset'     => 'iso-8859-1',
                'smtp_timeout' => 30,
                'validate'  => TRUE
            );
            $this->load->library("email", $config);
        }
        $body_message = $message;
        $this->email->subject($subject);
        $this->email->from($this->data['site_email'],$this->input->post('name'));
        $this->email->to($email);
        $this->email->message($body_message);
        if($this->email->send())
        {
            $debug = array("error_email"=>$this->email->print_debugger());
            $this->session->set_userdata($debug);
            return TRUE;
        }
        else
        {
            $debug = array("error_email"=>$this->email->print_debugger());
            $this->session->set_userdata($debug);
            return FALSE;
        }
    }
}
?&gt;

If I see method index() this view the html when I'm doing submit the form CI showme:
Code:
Fatal error: Call to a member function subject() on a non-object in application\controllers\contact.php on line 66

The line is $this->email->subject() I don't understand what happened.

Best regards
#2

[eluser]Aken[/eluser]
The error means that your email library is not loading. It likely means this line is not validating as TRUE:

Code:
if($this->data['smtp_enable'] == TRUE)

Double check the info that your model function is returning to the variable $this->data, then go from there.
#3

[eluser]nicholas.byfleet[/eluser]
Your problem could be that $this->data['smtp_enable'] is false, which would cause the email library not to be loaded. Try either loading the email library in the constructor, adding it to autoload.php or loading the library as the first line of your function. My guess is that $this->settings_model->get_conf(array('class'=>'core')); is returning false for 'smtp_enable'. Hope this helps...
#4

[eluser]Ivan A. Zenteno[/eluser]
sorry for big lagg, but I'm do
Code:
print_r ($this->data);
the
Code:
$this->data['smtp_enable']
is True, becose in the log on system/log/ show me
Code:
DEBUG - 2009-09-11 21:39:38 --&gt; Email Class Initialized
ERROR - 2009-09-11 21:39:38 --&gt; Severity: Notice  --&gt; Undefined property: contact::$email \application\controllers\contact.php 66

Best regards
#5

[eluser]Ivan A. Zenteno[/eluser]
I upgraded to version 1.7.2 and the error still appears no longer to do.
The new code is here url of code if some like to see it and help me a little bit.
This is the debug log.
Code:
DEBUG - 2009-09-15 00:48:01 --&gt; Language file loaded: language/spanish/form_validation_lang.php
DEBUG - 2009-09-15 00:48:01 --&gt; XSS Filtering completed
DEBUG - 2009-09-15 00:48:01 --&gt; XSS Filtering completed
DEBUG - 2009-09-15 00:48:01 --&gt; XSS Filtering completed
DEBUG - 2009-09-15 00:48:01 --&gt; Email Class Initialized
INFO  - 2009-09-15 00:48:01 --&gt; loading email     library with $config.
ERROR - 2009-09-15 00:48:01 --&gt; Severity: Notice  --&gt; Undefined property: contact::$email /application/controllers/contact.php 78
DEBUG - 2009-09-15 00:48:02 --&gt; Config Class Initialized
DEBUG - 2009-09-15 00:48:02 --&gt; Hooks Class Initialized
DEBUG - 2009-09-15 00:48:02 --&gt; URI Class Initialized
ERROR - 2009-09-15 00:48:02 --&gt; 404 Page Not Found --&gt; favicon.ico

The line 78 is :
Code:
$this->email->subject($subject);
#6

[eluser]Ivan A. Zenteno[/eluser]
I solved my problem, loading the email library within autoload file and put my class method initialize()

Thanks to all :lol:




Theme © iAndrew 2016 - Forum software by © MyBB