function send($newsletter_id) { global $messageStack; if (SEND_EMAILS != 'true') { $messageStack->add('news_email', ERROR_EMAIL_WAS_NOT_SENT, 'error'); return false; } $ids = $_GET['customers_chosen']; $mail_query = xos_db_query("select s.subscriber_id, s.subscriber_email_address, s.subscriber_identity_code, c.customers_firstname, c.customers_lastname from " . TABLE_NEWSLETTER_SUBSCRIBERS . " s left join " . TABLE_CUSTOMERS . " c on s.customers_id = c.customers_id where s.subscriber_id in (" . $ids . ") order by s.customers_id"); if (empty($this->language_directory)) { $lang_query = xos_db_query("select directory from " . TABLE_LANGUAGES . " where code = '" . xos_db_input(DEFAULT_LANGUAGE) . "'"); $lang = xos_db_fetch_array($lang_query); $this->language_directory = $lang['directory']; } //Let's build a message object using the mailer class $email_to_subscriber = new mailer(); $email_from_value = EMAIL_FROM; $from = html_entity_decode($email_from_value, ENT_QUOTES, 'UTF-8'); $address = ''; $name = ''; $pieces = explode('<', $from); if (count($pieces) == 2) { $address = trim($pieces[1], " >"); $name = trim($pieces[0]); } elseif (count($pieces) == 1) { $pos = stripos($pieces[0], '@'); $address = $pos ? trim($pieces[0], " >") : ''; } $email_to_subscriber->From = $address; $email_to_subscriber->FromName = $name; $email_to_subscriber->WordWrap = '100'; $email_to_subscriber->Subject = $this->title; $smarty_newsletter = new Smarty(); $smarty_newsletter->template_dir = DIR_FS_SMARTY . 'catalog/templates/'; $smarty_newsletter->compile_dir = DIR_FS_SMARTY . 'catalog/templates_c/'; $smarty_newsletter->config_dir = DIR_FS_SMARTY . 'catalog/'; $smarty_newsletter->cache_dir = DIR_FS_SMARTY . 'catalog/cache/'; $smarty_newsletter->left_delimiter = '[@{'; $smarty_newsletter->right_delimiter = '}@]'; $is_html = false; if ($this->content_text_htlm != '' && EMAIL_USE_HTML == 'true') { $is_html = true; $smarty_newsletter->assign(array('nl' => "\n", 'html_params' => HTML_PARAMS, 'xhtml_lang' => !empty($this->language_code) ? $this->language_code : DEFAULT_LANGUAGE, 'charset' => CHARSET, 'base_href' => substr(HTTP_SERVER, -1) == '/' ? HTTP_SERVER : '', 'content_text_htlm' => $this->content_text_htlm, 'content_text_plain' => $this->content_text_plain)); $smarty_newsletter->configLoad('languages/' . $this->language_directory . '_email.conf', 'newsletter_email_html'); $output_newsletter_email_html = $smarty_newsletter->fetch(DEFAULT_TPL . '/includes/email/newsletter_email_html.tpl'); $smarty_newsletter->configLoad('languages/' . $this->language_directory . '_email.conf', 'newsletter_email_text'); $output_newsletter_email_text = $smarty_newsletter->fetch(DEFAULT_TPL . '/includes/email/newsletter_email_text.tpl'); $email_to_subscriber->isHTML(true); } else { $smarty_newsletter->assign(array('nl' => "\n", 'content_text_plain' => $this->content_text_plain)); $smarty_newsletter->configLoad('languages/' . $this->language_directory . '_email.conf', 'newsletter_email_text'); $output_newsletter_email_text = $smarty_newsletter->fetch(DEFAULT_TPL . '/includes/email/newsletter_email_text.tpl'); $email_to_subscriber->isHTML(false); } while ($mail = xos_db_fetch_array($mail_query)) { $link_unsubscribe = xos_catalog_href_link('newsletter_subscribe.php', 'action=unsubscribe&identity_code=' . $mail['subscriber_identity_code'], 'SSL'); if ($is_html) { $email_to_subscriber->Body = $output_newsletter_email_html . '<a href="' . $link_unsubscribe . '" target="_blank">' . $link_unsubscribe . '</a>' . "\n" . '</div>' . "\n" . '</body>' . "\n" . '</html>' . "\n"; $email_to_subscriber->AltBody = html_entity_decode(strip_tags($output_newsletter_email_text . $link_unsubscribe), ENT_QUOTES, 'UTF-8'); } else { $email_to_subscriber->Body = html_entity_decode(strip_tags($output_newsletter_email_text . $link_unsubscribe), ENT_QUOTES, 'UTF-8'); } $email_to_subscriber->addAddress($mail['subscriber_email_address'], $mail['customers_firstname'] . ' ' . $mail['customers_lastname']); if (!$email_to_subscriber->send()) { $messageStack->add('news_email', sprintf(ERROR_PHP_MAILER, $email_to_subscriber->ErrorInfo, '<' . $mail['subscriber_email_address'] . '>'), 'error'); } else { $messageStack->add('news_email', sprintf(NOTICE_EMAIL_SENT_TO, '<' . $mail['subscriber_email_address'] . '>'), 'success'); } $email_to_subscriber->clearAddresses(); } $newsletter_id = xos_db_prepare_input($newsletter_id); xos_db_query("update " . TABLE_NEWSLETTERS . " set date_sent = now(), status = '1', locked = '0' where newsletters_id = '" . xos_db_input($newsletter_id) . "'"); }
function send($newsletter_id) { global $messageStack; if (SEND_EMAILS != 'true') { $messageStack->add('news_email', ERROR_EMAIL_WAS_NOT_SENT, 'error'); return false; } $audience = array(); $ids = $_GET['customers_chosen']; $customers_query = xos_db_query("select c.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address from " . TABLE_CUSTOMERS . " c where c.customers_id in (" . $ids . ")"); while ($customers = xos_db_fetch_array($customers_query)) { $audience[$customers['customers_id']] = array('firstname' => $customers['customers_firstname'], 'lastname' => $customers['customers_lastname'], 'email_address' => $customers['customers_email_address']); } if (empty($this->language_directory)) { $lang_query = xos_db_query("select directory from " . TABLE_LANGUAGES . " where code = '" . xos_db_input(DEFAULT_LANGUAGE) . "'"); $lang = xos_db_fetch_array($lang_query); $this->language_directory = $lang['directory']; } //Let's build a message object using the mailer class $email_to_customer = new mailer(); $email_from_value = EMAIL_FROM; $from = html_entity_decode($email_from_value, ENT_QUOTES, 'UTF-8'); $address = ''; $name = ''; $pieces = explode('<', $from); if (count($pieces) == 2) { $address = trim($pieces[1], " >"); $name = trim($pieces[0]); } elseif (count($pieces) == 1) { $pos = stripos($pieces[0], '@'); $address = $pos ? trim($pieces[0], " >") : ''; } $email_to_customer->From = $address; $email_to_customer->FromName = $name; $email_to_customer->WordWrap = '100'; $email_to_customer->Subject = $this->title; $smarty_product_notification = new Smarty(); $smarty_product_notification->template_dir = DIR_FS_SMARTY . 'catalog/templates/'; $smarty_product_notification->compile_dir = DIR_FS_SMARTY . 'catalog/templates_c/'; $smarty_product_notification->config_dir = DIR_FS_SMARTY . 'catalog/'; $smarty_product_notification->cache_dir = DIR_FS_SMARTY . 'catalog/cache/'; $smarty_product_notification->left_delimiter = '[@{'; $smarty_product_notification->right_delimiter = '}@]'; $is_html = false; if ($this->content_text_htlm != '' && EMAIL_USE_HTML == 'true') { $is_html = true; $smarty_product_notification->assign(array('html_params' => HTML_PARAMS, 'xhtml_lang' => !empty($this->language_code) ? $this->language_code : DEFAULT_LANGUAGE, 'charset' => CHARSET, 'base_href' => substr(HTTP_SERVER, -1) == '/' ? HTTP_SERVER : '', 'content_text_htlm' => $this->content_text_htlm, 'content_text_plain' => $this->content_text_plain)); $smarty_product_notification->configLoad('languages/' . $this->language_directory . '_email.conf', 'product_notification_email_html.tpl'); $output_product_notification_email_html = $smarty_product_notification->fetch(DEFAULT_TPL . '/includes/email/product_notification_email_html.tpl'); $smarty_product_notification->configLoad('languages/' . $this->language_directory . '_email.conf', 'product_notification_email_text.tpl'); $output_product_notification_email_text = $smarty_product_notification->fetch(DEFAULT_TPL . '/includes/email/product_notification_email_text.tpl'); $email_to_customer->isHTML(true); } else { $smarty_product_notification->assign('content_text_plain', $this->content_text_plain); $smarty_product_notification->configLoad('languages/' . $this->language_directory . '_email.conf', 'product_notification_email_text.tpl'); $output_product_notification_email_text = $smarty_product_notification->fetch(DEFAULT_TPL . '/includes/email/product_notification_email_text.tpl'); $email_to_customer->isHTML(false); } reset($audience); while (list($key, $value) = each($audience)) { if ($is_html) { $email_to_customer->Body = $output_product_notification_email_html; $email_to_customer->AltBody = html_entity_decode(strip_tags($output_product_notification_email_text), ENT_QUOTES, 'UTF-8'); } else { $email_to_customer->Body = html_entity_decode(strip_tags($output_product_notification_email_text), ENT_QUOTES, 'UTF-8'); } $email_to_customer->addAddress($value['email_address'], $value['firstname'] . ' ' . $value['lastname']); if (!$email_to_customer->send()) { $messageStack->add('news_email', sprintf(ERROR_PHP_MAILER, $email_to_customer->ErrorInfo, '<' . $value['email_address'] . '>'), 'error'); } else { $messageStack->add('news_email', sprintf(NOTICE_EMAIL_SENT_TO, '<' . $value['email_address'] . '>'), 'success'); } $email_to_customer->clearAddresses(); } $newsletter_id = xos_db_prepare_input($newsletter_id); xos_db_query("update " . TABLE_NEWSLETTERS . " set date_sent = now(), status = '1', locked = '0' where newsletters_id = '" . xos_db_input($newsletter_id) . "'"); }
$smarty_gv_email->configLoad('languages/' . $languages['directory'] . '_email.conf', 'gv_email_html'); $output_gv_email_html = $smarty_gv_email->fetch(DEFAULT_TPL . '/includes/email/gv_email_html.tpl'); $smarty_gv_email->configLoad('languages/' . $languages['directory'] . '_email.conf', 'gv_email_text'); $output_gv_email_text = $smarty_gv_email->fetch(DEFAULT_TPL . '/includes/email/gv_email_text.tpl'); $gv_email->isHTML(true); $gv_email->Body = $output_gv_email_html; $gv_email->AltBody = $output_gv_email_text; $gv_email->addEmbeddedImage(DIR_FS_CATALOG . (is_file(DIR_FS_CATALOG . 'images/email_shop_logo/' . EMAIL_SHOP_LOGO) ? 'images/email_shop_logo/' : 'images/catalog/templates/' . DEFAULT_TPL . '/') . EMAIL_SHOP_LOGO, 'shop_logo', '', 'base64', 'image/' . substr(strrchr(EMAIL_SHOP_LOGO, '.'), 1)); } else { $smarty_gv_email->assign(array('store_name_address' => STORE_NAME_ADDRESS, 'store_name' => STORE_NAME, 'gv_message' => $message, 'gv_id' => $id1, 'gv_amount' => $currencies->format($amount), 'link_shop' => xos_catalog_href_link(), 'link_gv_redeem' => xos_catalog_href_link(FILENAME_CATALOG_GV_REDEEM, 'gv_no=' . $id1, 'SSL'))); $smarty_gv_email->configLoad('languages/' . $languages['directory'] . '_email.conf', 'gv_email_text'); $output_gv_email_text = $smarty_gv_email->fetch(DEFAULT_TPL . '/includes/email/gv_email_text.tpl'); $gv_email->isHTML(false); $gv_email->Body = $output_gv_email_text; } $gv_email->addAddress($mail_sent_to); if (!$gv_email->send()) { $mailer_error = true; $messageStack->add_session('header', sprintf(ERROR_PHP_MAILER, $gv_email->ErrorInfo, $mail_sent_to), 'error'); } else { // Now create the coupon email entry xos_db_query("insert into " . TABLE_COUPONS . " (coupon_code, coupon_type, coupon_amount, date_created) values ('" . $id1 . "', 'G', '" . $amount . "', now())"); $insert_id = xos_db_insert_id(); xos_db_query("insert into " . TABLE_COUPON_EMAIL_TRACK . " (coupon_id, customer_id_sent, sent_firstname, emailed_to, date_sent) values ('" . $insert_id . "', '0', 'Admin', '" . $mail_sent_to . "', now() )"); } $_SESSION['used_lng_id'] = $used_lang_id; } else { $used_lang_id = $_SESSION['used_lng_id']; while ($mail = xos_db_fetch_array($mail_query)) { $id1 = create_coupon_code($mail['customers_email_address']); $languages_query = xos_db_query("select languages_id, code, directory from " . TABLE_LANGUAGES . " where use_in_id > '1' and languages_id = '" . $mail['language_id'] . "'");
if (count($pieces) == 2) { $address = trim($pieces[1], " >"); $name = trim($pieces[0]); } elseif (count($pieces) == 1) { $pos = stripos($pieces[0], '@'); $address = $pos ? trim($pieces[0], " >") : ''; } $email_to_customer->From = $address; $email_to_customer->FromName = $name; // $email_to_customer->WordWrap = ''; $email_to_customer->Subject = $subject; $email_to_customer->isHTML(false); $email_to_customer->Body = strip_tags($message); $mailer_error = false; while ($mail = xos_db_fetch_array($mail_query)) { $email_to_customer->addAddress($mail['customers_email_address'], $mail['customers_firstname'] . ' ' . $mail['customers_lastname']); if (!$email_to_customer->send()) { $mailer_error = true; $messageStack->add_session('header', sprintf(ERROR_PHP_MAILER, $email_to_customer->ErrorInfo, $mail['customers_email_address']), 'error'); } $email_to_customer->clearAddresses(); } if ($mailer_error == false) { $messageStack->add_session('header', sprintf(NOTICE_EMAIL_SENT_TO, $mail_sent_to), 'success'); } xos_redirect(xos_href_link(FILENAME_MAIL)); } } if ($action == 'preview' && empty($_POST['customers_email_address'])) { $messageStack->add('header', ERROR_NO_CUSTOMER_SELECTED, 'error'); }