function zen_build_html_email_from_template($module = 'default', $block) { // Identify and Read the template file for the type of message being sent $template_filename_base = DIR_FS_EMAIL_TEMPLATES . "email_template_"; if (file_exists($template_filename_base . str_replace(array('_extra', '_admin'), '', $module) . '.html')) { $template_filename = $template_filename_base . str_replace(array('_extra', '_admin'), '', $module) . '.html'; } elseif (file_exists($template_filename_base . 'default' . '.html')) { $template_filename = $template_filename_base . 'default' . '.html'; } else { echo 'ERROR: The email template file for ' . $template_filename_base . ' or ' . $template_filename . ' cannot be found.'; return ''; // couldn't find template file, so return an empty string for html message. } if (!($fh = fopen($template_filename, 'rb'))) { // note: the 'b' is for compatibility with Windows systems echo 'ERROR: The email template file ' . $template_filename_base . ' or ' . $template_filename . ' cannot be opened'; } $file_holder = fread($fh, filesize($template_filename)); fclose($fh); //strip linebreaks and tabs out of the template $file_holder = zen_convert_linefeeds(array("\r\n", "\n", "\r", "\t"), '', $file_holder); //check for some specifics that need to be included with all messages if ($block['EMAIL_STORE_NAME'] == '') { $block['EMAIL_STORE_NAME'] = STORE_NAME; } if ($block['EMAIL_STORE_URL'] == '') { $block['EMAIL_STORE_URL'] = '<a href="' . HTTP_CATALOG_SERVER . DIR_WS_CATALOG . '">' . STORE_NAME . '</a>'; } if ($block['EMAIL_STORE_OWNER'] == '') { $block['EMAIL_STORE_OWNER'] = STORE_OWNER; } if ($block['EMAIL_FOOTER_COPYRIGHT'] == '') { $block['EMAIL_FOOTER_COPYRIGHT'] = EMAIL_FOOTER_COPYRIGHT; } if ($block['EMAIL_DISCLAIMER'] == '') { $block['EMAIL_DISCLAIMER'] = sprintf(EMAIL_DISCLAIMER, '<a href="mailto:' . STORE_OWNER_EMAIL_ADDRESS . '">' . STORE_OWNER_EMAIL_ADDRESS . ' </a>'); } if ($block['EMAIL_SPAM_DISCLAIMER'] == '') { $block['EMAIL_SPAM_DISCLAIMER'] = EMAIL_SPAM_DISCLAIMER; } if ($block['BASE_HREF'] == '') { $block['BASE_HREF'] = HTTP_SERVER . DIR_WS_CATALOG; } if ($block['EMAIL_DATE_SHORT'] == '') { $block['EMAIL_DATE_SHORT'] = zen_date_short(date("Y-m-d")); } if ($block['EMAIL_DATE_LONG'] == '') { $block['EMAIL_DATE_LONG'] = zen_date_long(date("Y-m-d")); } if ($block['EXTRA_INFO'] == 'EXTRA_INFO') { $block['EXTRA_INFO'] = ''; } if (substr($module, -6) != '_extra' && $module != 'contact_us') { $block['EXTRA_INFO'] = ''; } $block['COUPON_BLOCK'] = ''; if ($block['COUPON_TEXT_VOUCHER_IS'] && $block['COUPON_TEXT_TO_REDEEM']) { $block['COUPON_BLOCK'] = '<div class="coupon-block">' . $block['COUPON_TEXT_VOUCHER_IS'] . $block['COUPON_DESCRIPTION'] . '<br />' . $block['COUPON_TEXT_TO_REDEEM'] . '<span class="coupon-code">' . $block['COUPON_CODE'] . '</span></div>'; } $block['GV_BLOCK'] = ''; if ($block['GV_WORTH'] && $block['GV_REDEEM'] && $block['GV_CODE_URL']) { $block['GV_BLOCK'] = '<div class="gv-block">' . $block['GV_WORTH'] . '<br />' . $block['GV_REDEEM'] . $block['GV_CODE_URL'] . '<br />' . $block['GV_LINK_OTHER'] . '</div>'; } //prepare the "unsubscribe" link: if (function_exists(zen_catalog_href_link)) { $block['UNSUBSCRIBE_LINK'] = str_replace("\n", '', TEXT_UNSUBSCRIBE) . ' <a href="' . zen_catalog_href_link(FILENAME_UNSUBSCRIBE, "unsubscribe_address=" . $block['EMAIL_TO_ADDRESS']) . '">' . zen_catalog_href_link(FILENAME_UNSUBSCRIBE, "unsubscribe_address=" . $block['EMAIL_TO_ADDRESS']) . '</a>'; } else { $block['UNSUBSCRIBE_LINK'] = str_replace("\n", '', TEXT_UNSUBSCRIBE) . ' <a href="' . zen_href_link(FILENAME_UNSUBSCRIBE, "unsubscribe_address=" . $block['EMAIL_TO_ADDRESS']) . '">' . zen_href_link(FILENAME_UNSUBSCRIBE, "unsubscribe_address=" . $block['EMAIL_TO_ADDRESS']) . '</a>'; } //now replace the $BLOCK_NAME items in the template file with the values passed to this function's array foreach ($block as $key => $value) { $file_holder = str_replace('$' . $key, $value, $file_holder); } //DEBUG -- to display preview on-screen if (EMAIL_SYSTEM_DEBUG == 'on') { echo $file_holder; } return $file_holder; }
/** * Adds a html part to the mail. * Also replaces image names with * content-id's. */ function add_html($html, $text = NULL, $images_dir = NULL) { $this->html = zen_convert_linefeeds(array("\r\n", "\n", "\r"), '<br />', $html); $this->html_text = zen_convert_linefeeds(array("\r\n", "\n", "\r"), $this->lf, $text); if (isset($images_dir)) { $this->find_html_images($images_dir); } }