public function setMailBody($data, $template_html = null, $format = 'HTML')
   {
      if ( !is_array($data) && $template_html == null ) {

         if ( $format == 'TEXT' ) {
            $this->isHTML = false;
            return $this->textBody = $data;
         }
         return $this->htmlBody = $data;

      } elseif ( is_array($data) && $template_html == null ) {

         return $this->htmlBody = implode('<br>  ', $data);

      } else {

         $templatePath = ($this->TemplateFolder)
               ? $this->TemplateFolder . '/' . $template_html
               : $template_html;
         // Support load different path to views available in CI v3.0
         if ( defined('VIEWPATH') ) {
            $views_path = VIEWPATH;
         } else {
            $views_path = APPPATH .'views/';
         }

         if ( !file_exists( $views_path . $templatePath ) ) {

            log_message('error','setEmailBody() HTML template file not found: ' . $template_html);
            return $this->htmlBody = 'Template ' . ($template_html) . ' not found.'; //'none template message found in: ' .$template_html;

         } else {

            $this->htmlBody = $this->CI->load->view($templatePath, '', true);

            if ( preg_match('/\.txt$/', $template_html) ) {

               $this->textBody = $this->htmlBody;

            } else {

               $templateTextPath = preg_replace('/\.[html|php|htm]+$/', '.txt', $templatePath);

               if ( file_exists( $views_path . $templateTextPath ) ) {

                  $this->textBody = $this->CI->load->view($templateTextPath, '', true);
               }
            }

         }

         $data = (is_array($data)) ? $data : array($data);
         $data = array_merge($data, $this->TemplateOptions);

         if ( $format == 'HTML' ) {

            foreach ($data as $key => $value) {
               $this->htmlBody = str_replace("{".$key."}", "".$value."", $this->htmlBody);
               $this->textBody = str_replace("{".$key."}", "".$value."", $this->textBody);
            }

         } elseif ( $format == 'TEXT' ) {

            $this->isHTML = false;
            $this->textBody = @vsprintf($this->textBody, $data);

         }
      }
   }
public function setMailBody($data, $template_html = null, $format = 'HTML')
   {
      if ( !is_array($data) && $template_html == null ) {

         if ( $format == 'TEXT' ) {
            $this->isHTML = false;
            return $this->textBody = $data;
         }
         return $this->htmlBody = $data;

      } elseif ( is_array($data) && $template_html == null ) {

         return $this->htmlBody = implode('<br>  ', $data);

      } else {

         $templatePath = ($this->TemplateFolder)
               ? $this->TemplateFolder . '/' . $template_html
               : $template_html;
         // Support load different path to views available in CI v3.0
         if ( defined('VIEWPATH') ) {
            $views_path = VIEWPATH;
         } else {
            $views_path = APPPATH .'views/';
         }

         if ( !file_exists( $views_path . $templatePath ) ) {

            log_message('error','setEmailBody() HTML template file not found: ' . $template_html);
            return $this->htmlBody = 'Template ' . ($template_html) . ' not found.'; //'none template message found in: ' .$template_html;

         } else {

            $this->htmlBody = $this->CI->load->view($templatePath, '', true);

            if ( preg_match('/\.txt$/', $template_html) ) {

               $this->textBody = $this->htmlBody;

            } else {

               $templateTextPath = preg_replace('/\.[html|php|htm]+$/', '.txt', $templatePath);

               if ( file_exists( $views_path . $templateTextPath ) ) {

                  $this->textBody = $this->CI->load->view($templateTextPath, '', true);
               }
            }

         }

         $data = (is_array($data)) ? $data : array($data);
         $data = array_merge($data, $this->TemplateOptions);

         if ( $format == 'HTML' ) {

            foreach ($data as $key => $value) {
               $this->htmlBody = str_replace("{".$key."}", "".$value."", $this->htmlBody);
               $this->textBody = str_replace("{".$key."}", "".$value."", $this->textBody);
            }

         } elseif ( $format == 'TEXT' ) {

            $this->isHTML = false;
            $this->textBody = @vsprintf($this->textBody, $data);

         }
      }
   }
public function setMailBody ( $ data , $ template_html = null , $ format = 'HTML' ) { if ( ! is_array ( $ data ) && $ template_html == null ) { if ( $ format == 'TEXT' ) { $ this -> isHTML = false ; return $ this -> textBody = $ data ; } return $ this -> htmlBody = $ data ; } elseif ( is_array ( $ data ) && $ template_html == null ) { return $ this -> htmlBody = implode ( '<br>  ' , $ data ) ; } else { $ templatePath = ( $ this -> TemplateFolder ) ? $ this -> TemplateFolder . '/' . $ template_html : $ template_html ; // Support load different path to views available in CI v3.0 if ( defined ( 'VIEWPATH' ) ) { $ views_path = VIEWPATH ; } else { $ views_path = APPPATH . 'views/' ; } if ( ! file_exists ( $ views_path . $ templatePath ) ) { log_message ( 'error' , 'setEmailBody() HTML template file not found: ' . $ template_html ) ; return $ this -> htmlBody = 'Template ' . ( $ template_html ) . ' not found.' ; //'none template message found in: ' .$template_html; } else { $ this -> htmlBody = $ this -> CI -> load -> view ( $ templatePath , '' , true ) ; if ( preg_match ( '/\.txt$/' , $ template_html ) ) { $ this -> textBody = $ this -> htmlBody ; } else { $ templateTextPath = preg_replace ( '/\.[html|php|htm]+$/' , '.txt' , $ templatePath ) ; if ( file_exists ( $ views_path . $ templateTextPath ) ) { $ this -> textBody = $ this -> CI -> load -> view ( $ templateTextPath , '' , true ) ; } } } $ data = ( is_array ( $ data ) ) ? $ data : array ( $ data ) ; $ data = array_merge ( $ data , $ this -> TemplateOptions ) ; if ( $ format == 'HTML' ) { foreach ( $ data as $ key => $ value ) { $ this -> htmlBody = str_replace ( "{" . $ key . "}" , "" . $ value . "" , $ this -> htmlBody ) ; $ this -> textBody = str_replace ( "{" . $ key . "}" , "" . $ value . "" , $ this -> textBody ) ; } } elseif ( $ format == 'TEXT' ) { $ this -> isHTML = false ; $ this -> textBody = @ vsprintf ( $ this -> textBody , $ data ) ; } } }
Set Mail Body configuration

Format email message Body, this can be an external template html file with a copy
of a plain-text like template.txt or HTML/plain-text string.
This method can be used by passing a template file HTML name and an associative array
with the values that can be parsed into the file HTML by the key KEY_NAME found in your
array to your HTML {KEY_NAME}.
Other optional ways to format the mail body is available like instead of a template the
param $data can be set as an array or string, but param $template_html must be equal to null

@update 2014-04-01 01:46
@author Adriano Rosa (http://adrianorosa.com)
@param mixed  $data [array|string] that contain the values to be parsed in mail body
@param string $template_html the external html template filename , OR the message as HMTL string
@param string $format [HTML|TEXT]
@return string
Set Mail Body configuration