Here is an example of how I make a custom lib email, it is for your reference on how I do it
Code:
/**
@author : yourname
*/
// 1. google and copy the phpmailer class
// 2. put this class under application/libraries
// 3. and your custom class Myemail
// 4. Config email.php to your setting, assume use of gmail but you can use any of your email server
// copy email.php to application/config
class Myemail {
protected $CI;
function __construct(){
$CI = &get_instance();
$CI->config->load('email'); // specific config email file
$CI->load->library('phpmailer'); // I use phpmailer as third party email program
}
function sendEmail($email_from,$name_from,$subject,$message, $mailto, $name_mailto=NULL){
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->Host=$CI->config->item('smtp_host');
$mail->SMTPDebug = 0; // enables SMTP debug
$mail->AddAddress($mailto, $name_mailto);
$mail->SetFrom($email_from, $name_from);
$mail->AddReplyTo($email_from, $name_from);
$mail->Subject = $subject;
$mail->AltBody = 'Please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($message);
$status=$mail->Send();
//return boolean true as 1
if(!$status){
throw new Exception($mail->ErrorInfo);
}else{
if($mail->ErrorInfo!==''){
return FALSE;
}
else{
return TRUE;
}
}
} catch (phpmailerException $e) {
return $e->errorMessage();
} catch (Exception $e) {
return $e->getMessage();
}
}// end function email
}
/* below is email.php as sample config file and put this under application/config*/
/*
smtp_host No Default None SMTP Server Address.
smtp_user No Default None SMTP Username.
smtp_pass No Default None SMTP Password.
smtp_port 25 None SMTP Port.
smtp_timeout 5 None SMTP Timeout (in seconds).
wordwrap TRUE TRUE or FALSE (boolean) Enable word-wrap.
*/
$config['protocol'] = 'smtp';
$config['mailpath'] = ''; //'/usr/sbin/sendmail';
$config['smtp_host'] = ''; //smtp-relay.gmail.com';//
$config['smtp_user'] = 'youruser';
$config['smtp_pass']= 'password';
$config['smtp_port']= 587;
$config['smtp_timeout']=5;
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['email_default']='';
/* END email.php config file*/