function sendMessagesPortion3($num) { global $application; loadCoreFile('ascHtmlMimeMail.php'); $mailer = new ascHtmlMimeMail(); $tables = $this->getTables(); $table = 'newsletter_temp'; $columns =& $tables[$table]['columns']; $query = new DB_Select($table); $query->addSelectField($columns['recipient_value']); $query->addSelectField($columns['key_unsubscribe']); $query->addSelectField($columns['lng']); $query->WhereValue($columns['recipient_num'], DB_EQ, $num); $query->SelectOrder($columns['recipient_id'], 'ASC'); $query->SelectLimit(0, PORTION_MAX_MESSAGES_NUM); $res = $application->db->getDB_Result($query); $addr_num = count($res); $start_time = $this->microtime_float(); $sent_count = 0; // getting the default language $default_language = modApiFunc('MultiLang', 'getDefaultLanguage'); // saving the current language $current_language = modApiFunc('MultiLang', 'getLanguage'); // storing the current letter_id $letter_id = $this->_currentMessage['letter_id']; while ($this->microtime_float() - $start_time < PORTION_MAX_EXPORT_TIME && $sent_count < $addr_num) { // // // // setting the language if (!$res[$sent_count]['lng']) { $res[$sent_count]['lng'] = $default_language; } modApiFunc('MultiLang', 'setLanguage', $res[$sent_count]['lng']); // reading the newsletter for the language $this->_currentMessage = $this->getMessageInfo($letter_id); $from = $this->_currentMessage['letter_from_name'] . ' <' . $this->_currentMessage['letter_from_email'] . '>'; $mailer->setFrom($from); $mailer->setSubject($this->_currentMessage['letter_subject']); $html_tmpl = "<html><head><title>{$this->_currentMessage['letter_subject']}</title></head><body>{$this->_currentMessage['letter_html']}</body></html>"; $html_log = str_replace('%KEY_UNSUBSCRIBE%', $res[$sent_count]['key_unsubscribe'], $this->_currentMessage['letter_html']); $mailer->setHtml(str_replace('%KEY_UNSUBSCRIBE%', $res[$sent_count]['key_unsubscribe'], $html_tmpl)); $result = $mailer->send(array($res[$sent_count]['recipient_value'])); $mailer->resetMessageBuilt(); $this->addNewsletterToTimeline($res[$sent_count]['recipient_value'], $this->_currentMessage['letter_subject'], $html_log, $result); $sent_count++; // : /*debug*/ //usleep(200000); } // restoring the current language modApiFunc('MultiLang', 'setLanguage', $current_language); if ($sent_count) { $this->_sentCountTotal += $sent_count; $this->removeEmails($num, $sent_count); } if ($this->_sentCountTotal < $this->_totalRecipients) { $sending_status = 'PROCESSING'; } else { $sending_status = 'COMPLETED'; $this->_sentCountTotal = $this->_totalRecipients; $this->updateMessage($this->_currentMessage['letter_id'], array('letter_sent_date' => date('Y-m-d G:i:s'))); } return array('errors' => '', 'warnings' => '', 'sent_total' => $this->_sentCountTotal, 'sending_status' => $sending_status); }