Create a library with the name of "myemail" and place that in application/libraries.
application/libraries/myemail.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class CI_Myemail
{
public function __construct()
{
$this->CI =& get_instance();
}
public function saveEmail($to,$body,$subject)
{
$this->CI->load->model("table_model");
$this->table_model->save(array("to"=>$to,"body"=>$body,"subject"=>$subject,"mail_sent_time"=>date("Y-m-d H:i:s")));
}
}
Then you have to create table_model and write function to save the data into data.
In controller, you have to load this library as
$this->load->library('myemail');
In controller, you have to call as
$this->myemail->saveEmail($this->to,$body,$subject);// Here, $this->do is controller variable as you mentioned in comment