I am using codeigniter 3.1.2
I want to separate email methods into a separate file of its own, and call on them as needed. Much like how one can call methods in a model from controller with $this->Some_model->some_method();
From my understanding, it would be best to do this via libraries?
But I am having trouble understanding how to set it up.
Below is my attempt to make it work
In my controller I have
$this->load->library('CustomEmail');
$result = $this->CustomEmail->email_reciept($emailaddress,$orderinfo);
In my application/library
folder I have a file called CustomEmail.php
. In that file is
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class CustomEmail {
public function email_receipt($emailaddress,$orderinfo){
//codes related to config, prepare and sending email message
//the code can email properly if I use it directly in controller
//but I want to avoid repeating this code in every place I want to send email
}
}