application/libraries/Message_library.php
// Generic function to send an email using configuration defaults when needed
Generic function to send an email using configuration defaults when needed
Generic function to send an email using configuration defaults when needed
public function sendEmail($message, $format = 'html', $log = false) {
        if(isset($message['to'])) {
            if(!isset($message['from_email'])) {
                $message['from_email'] = $this->CI->config_model->getOption('default_from_email');
            }
            if(!isset($message['from_name'])) {
                $message['from_name'] = $this->CI->config_model->getOption('default_from_name');
            }
            $this->email_config['mailtype'] = $format;
            $this->CI->email->initialize($this->email_config);
            $this->CI->email->from($message['from_email'], $message['from_name']);
            $this->CI->email->to($message['to']);
            $this->CI->email->subject($message['subject']);
            $this->CI->email->message($message['message']);
            if(isset($message['alt_message']) && !empty($message['alt_message'])) {
                $this->CI->email->set_alt_message($message['alt_message']);
            }
            if(isset($message['attachment']) && !empty($message['attachment'])) {
                $this->CI->email->attach($message['attachment']);
            }
            $return = $this->CI->email->send();
            if($return && $log) {
                $message['status'] = 'sent';
                $this->CI->message_model->setMessage($message);
            }
            return $return;
        } else {
            return false;
        }
    }
public function sendEmail ( $ message , $ format = 'html' , $ log = false ) { if ( isset ( $ message [ 'to' ] ) ) { if ( ! isset ( $ message [ 'from_email' ] ) ) { $ message [ 'from_email' ] = $ this -> CI -> config_model -> getOption ( 'default_from_email' ) ; } if ( ! isset ( $ message [ 'from_name' ] ) ) { $ message [ 'from_name' ] = $ this -> CI -> config_model -> getOption ( 'default_from_name' ) ; } $ this -> email_config [ 'mailtype' ] = $ format ; $ this -> CI -> email -> initialize ( $ this -> email_config ) ; $ this -> CI -> email -> from ( $ message [ 'from_email' ] , $ message [ 'from_name' ] ) ; $ this -> CI -> email -> to ( $ message [ 'to' ] ) ; $ this -> CI -> email -> subject ( $ message [ 'subject' ] ) ; $ this -> CI -> email -> message ( $ message [ 'message' ] ) ; if ( isset ( $ message [ 'alt_message' ] ) && ! empty ( $ message [ 'alt_message' ] ) ) { $ this -> CI -> email -> set_alt_message ( $ message [ 'alt_message' ] ) ; } if ( isset ( $ message [ 'attachment' ] ) && ! empty ( $ message [ 'attachment' ] ) ) { $ this -> CI -> email -> attach ( $ message [ 'attachment' ] ) ; } $ return = $ this -> CI -> email -> send ( ) ; if ( $ return && $ log ) { $ message [ 'status' ] = 'sent' ; $ this -> CI -> message_model -> setMessage ( $ message ) ; } return $ return ; } else { return false ; } }
Generic function to send an email using configuration defaults when needed
Generic function to send an email using configuration defaults when needed
// If we don't have "from" info use the defaults configured for the system // Initialize and send the message // If we want to log the message do so