load->library('email'); $ci->load->library('MailLib'); $sancho_mail_config = $ci->config->item('mail'); if ($from == '') { $from = ((isset($sancho_mail_config['sancho_mail_default_sender']) && $sancho_mail_config['sancho_mail_default_sender']) ? $sancho_mail_config['sancho_mail_default_sender'] : 'noreply') . '@' . DOMAIN; } // Embed sancho header and footer image // reset important to ensure embedding of images when called in a loop $ci->email->clear(true); // clear vars and attachments $cid_header = ''; $cid_footer = ''; if (isset($sancho_mail_config['sancho_mail_use_images']) && $sancho_mail_config['sancho_mail_use_images']) { $sanchoHeader_img = ''; $sanchoFooter_img = ''; if (isset($headerImg) && $headerImg != '') { // use provided header image $sanchoHeader_img = $headerImg; } elseif (isset($sancho_mail_config['sancho_mail_header_img']) && $sancho_mail_config['sancho_mail_header_img']) { // use default header image $sanchoHeader_img = $sancho_mail_config['sancho_mail_header_img']; } if (isset($footerImg) && $footerImg != '') { // use provided footer image $sanchoFooter_img = $footerImg; } elseif (isset($sancho_mail_config['sancho_mail_footer_img']) && $sancho_mail_config['sancho_mail_footer_img']) { // use default footer image $sanchoFooter_img = $sancho_mail_config['sancho_mail_footer_img']; } // add image file paths if (isset($sancho_mail_config['sancho_mail_img_path'])) { if ($sanchoHeader_img != '') { $sanchoHeader_img = $sancho_mail_config['sancho_mail_img_path'].$sanchoHeader_img; } if ($sanchoFooter_img != '') { $sanchoFooter_img = $sancho_mail_config['sancho_mail_img_path'].$sanchoFooter_img; } } // attach header and footer $ci->email->attach($sanchoHeader_img, 'inline'); $ci->email->attach($sanchoFooter_img, 'inline'); $cid_header = $ci->email->attachment_cid($sanchoHeader_img); // sets unique content id for embedding $cid_footer = $ci->email->attachment_cid($sanchoFooter_img); // sets unique content id for embedding } // Set specific mail content into specific content template $content = _parseMailContent($vorlage_kurzbz, $vorlage_data); // overall main content data array $layout = array( 'CID_header' => $cid_header, 'CID_footer' => $cid_footer, 'content' => $content ); // Set overall main content into the sancho mail template $body = _parseMailContent('Sancho_Mail_Template', $layout); // Send mail return $ci->maillib->send( $from, $to, $subject, $body, '', // alias $cc, $bcc, '', // altMessage true, // bulk true // autogenerated ); } /** * Replace variables in the mail content template with specific mail content data. * @param string $vorlage_kurzbz Name of the template for specific mail content. * @param array $vorlage_data Associative array with specific mail content varibales * to be replaced in the content template. * @return string */ function _parseMailContent($vorlage_kurzbz, $vorlage_data) { $ci =& get_instance(); $ci->load->library('VorlageLib'); $result = $ci->vorlagelib->loadVorlagetext($vorlage_kurzbz); if (isSuccess($result)) { // If the text and the subject of the template are not empty if (is_array($result->retval) && count($result->retval) > 0 && !isEmptyString($result->retval[0]->text)) { // Parses template text return parseText($result->retval[0]->text, $vorlage_data); } } }