Welcome Guest, Not a member yet? Register   Sign In
Make custom driver
#9

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*/
Reply


Messages In This Thread
Make custom driver - by omid_student - 09-20-2017, 01:58 AM
RE: Make custom driver - by rtenny - 09-20-2017, 08:01 AM
RE: Make custom driver - by omid_student - 09-21-2017, 01:05 AM
RE: Make custom driver - by rtenny - 09-21-2017, 04:23 AM
RE: Make custom driver - by omid_student - 09-24-2017, 02:00 AM
RE: Make custom driver - by XMadMax - 09-26-2017, 05:00 AM
RE: Make custom driver - by omid_student - 09-27-2017, 08:47 AM
RE: Make custom driver - by ciadvantage - 09-27-2017, 02:58 PM
RE: Make custom driver - by ciadvantage - 09-27-2017, 03:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB