Welcome Guest, Not a member yet? Register   Sign In
Call to a member function on a non-object Issue
#1

(This post was last modified: 08-06-2016, 12:09 AM by codeigniterd.)

I want to put all my email  send code from a library.

i have craeted a controller function resetPassword
controller is forgot_password.php
public function resetPassword()
    {
        //Reset Password Send Mail Code Here
        $this->load->helper('form');
        $this->load->library('form_validation','security');

        $this->form_validation->set_rules('email', 'Email address', 'trim|required|valid_email');
        if ($this->form_validation->run() == FALSE)
        {
            $message = array('type' => 'alert', 'text' => 'Please submit valid email !', 'title' => 'ERROR');
        }
        else
        {
            $this->load->model('login_model');
            $email = $this->input->post('email');
            $email = $this->security->xss_clean($email);
            $user_exists = $this->login_model->where('user_username', $email)->get();
            if($user_exists)
     {
                    $params = array(
                        'user_username'=>'hjsjajdjaa',
                        'link'=> 'link'
                    );
                    $this->load->library('backendEmailLibrary');
                    $responseFromMail = $this->backendEmailLibrary->sendResetPasswordMail($params);
                    if($responseFromMail)
                      echo 'success';
                }
            }
            else
            {
                   echo 'faliure';
            }
        }
       echo 'exit';
    }


my library
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class BackendEmailLibrary {

    protected $CI;
    // Constructor
    public function __construct()
    {
        $this->CI =& get_instance();
        $this->CI->load->model('login_model');
        if (ENVIRONMENT == 'production')
        {
            $config = Array(       
                'protocol' => 'sendmail',
                'smtp_host' => 'your domain SMTP host',
                'smtp_port' => 25,
                'smtp_user' => 'SMTP Username',
                'smtp_pass' => 'SMTP Password',
                'smtp_timeout' => '4',
                'mailtype'  => 'html',
                'charset'   => 'iso-8859-1'
            );
        }
        else
            $config = Array();
    }

    public function sendResetPasswordMail($params)
    {
        $user_username = $params['user_username'];
        $token_link = $params['token_link'];
        $subject = 'password reset mail';
        echo '<pre>'; print_r($config); die;
        $this->CI->load->library('email', $config);
        if(!empty($config))
        {
            //Reset Mail starts
            $this->CI->email->set_newline("\r\n");
            $this->CI->email->from('[email protected]', 'xxxx');
            $user_exists = $this->CI->login_model->where('user_username', $user_username)->get();
            $data = array(
                'pssrestmailName'=> $user_exists->user_fname,
                'pssrestmailToken'=> $link
            );
            $this->CI->email->to($user_exists->user_username);  // replace it with receiver mail id
            $this->CI->email->subject($subject); // replace it with relevant subject

            $body = $this->CI->load->view('emails/resetpassword.php',$data,TRUE);
            $this->CI->email->message($body);  
            $flag = $this->CI->email->send();
            return $flag;
        }
        else
            return false;
    }
}

=====================================================
I dont knw where from the error is coming from ? Please help


Severity: Notice
Message: Undefined property: Forgot_password::$backendEmailLibrary
Filename: controllers/forgot_password.php

Call to a member function sendResetPasswordMail() on a non-object in forgot_password.php on line Bolded area.
Reply


Messages In This Thread
Call to a member function on a non-object Issue - by codeigniterd - 08-06-2016, 12:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB