function send($newsletter_id) { $OSCOM_Db = Registry::get('Db'); $newsletterEmail = new Mail(); $newsletterEmail->setFrom(STORE_OWNER_EMAIL_ADDRESS, STORE_OWNER); $newsletterEmail->setSubject($this->title); if (!empty($this->content)) { $newsletterEmail->setBodyPlain($this->content); } if (!empty($this->content_html)) { $newsletterEmail->setBodyHTML($this->content_html); } $Qmail = $OSCOM_Db->get('customers', ['customers_firstname', 'customers_lastname', 'customers_email_address'], ['customers_newsletter' => '1']); while ($Qmail->fetch()) { $newsletterEmail->clearTo(); $newsletterEmail->addTo($Qmail->value('customers_email_address'), $Qmail->value('customers_firstname') . ' ' . $Qmail->value('customers_lastname')); $newsletterEmail->send(); } $OSCOM_Db->save('newsletters', ['date_sent' => 'now()', 'status' => '1'], ['newsletters_id' => (int) $newsletter_id]); }
$Qmail = $OSCOM_Db->get('customers', ['customers_firstname', 'customers_lastname', 'customers_email_address'], ['customers_email_address' => $customers_email_address]); $mail_sent_to = $customers_email_address; break; } $customerEmail = new Mail(); $customerEmail->setFrom($_POST['from']); $customerEmail->setSubject($_POST['subject']); if (!empty($_POST['message'])) { $customerEmail->setBodyPlain($_POST['message']); } if (!empty($_POST['message_html'])) { $customerEmail->setBodyHTML($_POST['message_html']); } while ($Qmail->fetch()) { $customerEmail->clearTo(); $customerEmail->addTo($Qmail->value('customers_email_address'), $Qmail->value('customers_firstname') . ' ' . $Qmail->value('customers_lastname')); $customerEmail->send(); } OSCOM::redirect(FILENAME_MAIL, 'mail_sent_to=' . urlencode($mail_sent_to)); } if ($action == 'preview' && !isset($_POST['customers_email_address'])) { $OSCOM_MessageStack->add(OSCOM::getDef('error_no_customer_selected'), 'error'); } if (isset($_GET['mail_sent_to'])) { $OSCOM_MessageStack->add(OSCOM::getDef('notice_email_sent_to', ['mail_sent_to' => $_GET['mail_sent_to']]), 'success'); } require $oscTemplate->getFile('template_top.php'); ?> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr>
function send($newsletter_id) { $OSCOM_Db = Registry::get('Db'); $audience = array(); if (isset($_POST['global']) && $_POST['global'] == 'true') { $Qproducts = $OSCOM_Db->get(['customers c', 'products_notifications pn'], ['distinct pn.customers_id', 'c.customers_firstname', 'c.customers_lastname', 'c.customers_email_address'], ['c.customers_id' => ['rel' => 'pn.customers_id']]); while ($Qproducts->fetch()) { $audience[$Qproducts->valueInt('customers_id')] = ['firstname' => $Qproducts->value('customers_firstname'), 'lastname' => $Qproducts->value('customers_lastname'), 'email_address' => $Qproducts->value('customers_email_address')]; } $Qcustomers = $OSCOM_Db->get(['customers c', 'customers_info ci'], ['c.customers_id', 'c.customers_firstname', 'c.customers_lastname', 'c.customers_email_address'], ['c.customers_id' => ['rel' => 'ci.customers_info_id'], 'ci.global_product_notifications' => '1']); while ($Qcustomers->fetch()) { $audience[$Qcustomers->valueInt('customers_id')] = ['firstname' => $Qcustomers->value('customers_firstname'), 'lastname' => $Qcustomers->value('customers_lastname'), 'email_address' => $Qcustomers->value('customers_email_address')]; } } else { $chosen = []; foreach ($_POST['chosen'] as $id) { if (is_numeric($id) && !in_array($id, $chosen)) { $chosen[] = $id; } } $ids = array_map(function ($k) { return ':products_id_' . $k; }, array_keys($chosen)); $Qproducts = $OSCOM_Db->prepare('select distinct pn.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address from :table_customers c, :table_products_notifications pn where c.customers_id = pn.customers_id and pn.products_id in (' . implode(', ', $ids) . ')'); foreach ($chosen as $k => $v) { $Qproducts->bindInt(':products_id_' . $k, $v); } $Qproducts->execute(); while ($Qproducts->fetch()) { $audience[$Qproducts->valueInt('customers_id')] = ['firstname' => $Qproducts->value('customers_firstname'), 'lastname' => $Qproducts->value('customers_lastname'), 'email_address' => $Qproducts->value('customers_email_address')]; } $Qcustomers = $OSCOM_Db->get(['customers c', 'customers_info ci'], ['c.customers_id', 'c.customers_firstname', 'c.customers_lastname', 'c.customers_email_address'], ['c.customers_id' => ['rel' => 'ci.customers_info_id'], 'ci.global_product_notifications' => '1']); while ($Qcustomers->fetch()) { $audience[$Qcustomers->valueInt('customers_id')] = ['firstname' => $Qcustomers->value('customers_firstname'), 'lastname' => $Qcustomers->value('customers_lastname'), 'email_address' => $Qcustomers->value('customers_email_address')]; } } $notificationEmail = new Mail(); $notificationEmail->setFrom(STORE_OWNER_EMAIL_ADDRESS, STORE_OWNER); $notificationEmail->setSubject($this->title); if (!empty($this->content)) { $notificationEmail->setBodyPlain($this->content); } if (!empty($this->content_html)) { $notificationEmail->setBodyHTML($this->content_html); } foreach ($audience as $key => $value) { $notificationEmail->clearTo(); $notificationEmail->addTo($value['email_address'], $value['firstname'] . ' ' . $value['lastname']); $notificationEmail->send(); } $OSCOM_Db->save('newsletters', ['date_sent' => 'now()', 'status' => '1'], ['newsletters_id' => (int) $newsletter_id]); }