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);

         }
      }
   }