Aurora
Aurora

Reputation: 282

Codeigniter controller showing error

Hello I am using codeigniter controller to send emails, after getting data from the db. But the problem is when the email reaches $this->email->initialize($config); while debugging it crashes with the error

Severity: Notice

Message: Undefined property : Invoice::$email

Line Number: 563

Everything looks pretty fine, and I normally use this email functionality in a lot of places. But I cannot figure out the error. Here is the code in the controller.

public function sendReminderForUnpaidInvoice() {
        //fetch tha data from the database 
        $this->load->model('invoice_page');
        $foo = $this->invoice_page->get();
        $result = json_decode(json_encode($foo), true);
        foreach ($foo as $result){

            $this->load->library('../controllers/payment');
            $resultMangoPay = $this->payment->getMangopayPayinForTheInvoiceMail($result->rf_reference);
            $totalAmount = ($result->gross_amount) + ($result->type_related_amount) ;
            $this->load->library('email');
            $config['protocol'] = 'smtp';

            $config['smtp_host'] = 'ssl://smtp.gmail.com';

            $config['smtp_port']    = '465';

            $config['smtp_timeout'] = '7';

            $config['smtp_user']    = '[email protected]';

            $config['smtp_pass']    = '#########';

            $config['charset']    = 'utf-8';

            $config['newline']    = "\r\n";

            $config['mailtype'] = 'text'; // or html

            $config['validation'] = TRUE; // bool whether to validate email or not      

            $this->email->initialize($config); // line 563

            $this->email->from('[email protected]', 'aurora exchange');
            $this->email->to($result->Email);
            $this->email->subject('Repayment invoice');
            $this->email->message(
            'Hello '.$result->Fullname.'.'."\n"
            .'Here is a invoice for the next upcoming payment. '."\n"."\n"
            .'Payment should be done by bank transfer to the information provided below'."\n"
            .'Name :'.$resultMangoPay['OwnerName']
            .'IBAN :'.$resultMangoPay['IBAN']    
                    );  
            $returnvalue = $this->email->send();


            if(!$returnvalue) {
              return false;
            } else {  

               // will do something here later
            }
            $this->email->clear(TRUE);   
        }
    }

Upvotes: 1

Views: 88

Answers (2)

XAF
XAF

Reputation: 1472

You cannot load a codeigniter library or a model after you have loaded a controller, it breaks that way, if you load your email library and your model first and then load your payment controller, it should work as how it should.

Upvotes: 2

noufalcep
noufalcep

Reputation: 3536

Try initializing the library using the array.

$config = array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.gmail.com',
    'smtp_port' => 465,
    'smtp_timeout' => '7',
    'smtp_user' => '[email protected]',
    'smtp_pass' => '#########',
    'charset'   => 'utf-8',
    'newline'   => "\r\n",
    'mailtype'  => 'text',
    'validation' => TRUE
);

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

Upvotes: 0

Related Questions