/** * . PORTION_MAX_EXPORT_TIME . */ function sendMessagesPortion() { global $application; loadCoreFile('ascHtmlMimeMail.php'); $mailer = new ascHtmlMimeMail(); $from = $this->_currentMessage['letter_from_name'] . ' <' . $this->_currentMessage['letter_from_email'] . '>'; $mailer->setFrom($from); $mailer->setSubject($this->_currentMessage['letter_subject']); $html = "<html><head><title>{$this->_currentMessage['letter_subject']}</title></head><body>{$this->_currentMessage['letter_html']}</body></html>"; $mailer->setHtml($html); $start_time = $this->microtime_float(); $sent_count = 0; // // $max_to_send // $table = 'newsletter_temp'; $tables = $this->getTables(); // PORTION_MAX_MESSAGES_NUM , (_sentCountTotal + 1) // , PORTION_MAX_MESSAGES_NUM $query = new DB_Select(); $query->addSelectTable($table); $query->addSelectField($tables[$table]['columns']['recipient_value']); $query->addWhereOpenSection(); $query->WhereValue($tables[$table]['columns']['recipient_num'], DB_GTE, $this->_sentCountTotal + 1); $query->WhereAND(); $query->WhereValue($tables[$table]['columns']['recipient_num'], DB_LTE, $this->_sentCountTotal + PORTION_MAX_MESSAGES_NUM); $query->addWhereCloseSection(); $res = $application->db->getDB_Result($query); $addr_num = count($res); while ($this->microtime_float() - $start_time < PORTION_MAX_EXPORT_TIME && $sent_count < $addr_num) { // // // $mailer->send(array($res[$sent_count]['recipient_value'])); $sent_count++; // : /*debug*/ //usleep(200000); } $this->_sentCountTotal += $sent_count; $sending_status = 'PROCESSING'; if ($this->_sentCountTotal >= $this->_totalRecipients) { $this->_sentCountTotal = $this->_totalRecipients; // // // $table = 'newsletter_temp'; $tables = $this->getTables(); $query = new DB_Delete($table); $application->db->PrepareSQL($query); $application->db->DB_Exec(); $this->updateMessage($this->_currentMessage['letter_id'], array('letter_sent_date' => date('Y-m-d G:i:s'))); $sending_status = 'COMPLETED'; } return array('errors' => '', 'warnings' => '', 'sent_total' => $this->_sentCountTotal, 'sending_status' => $sending_status); }
/** * Sends a notification to each of the receiver. */ function send() { loadCoreFile('ascHtmlMimeMail.php'); if (!$this->haveToSend) { return; } if (Configuration::getSupportMode(ASC_S_NOTIFICATIONS)) { return; } // getting the recipients and languages $to = $this->getMLSendTo(); // adding third party emails to "To" array if (isset($this->thirdparty_emails) && is_array($this->thirdparty_emails) && !empty($this->thirdparty_emails)) { foreach ($this->thirdparty_emails as $i => $email) { $to[] = $email; } } // saving the current languages $cur_lng = modApiFunc('MultiLang', 'getLanguage'); $cur_res_lng = modApiFunc('MultiLang', 'getResourceLanguage'); // processing the recipients foreach ($to as $address) { // skipping invalid records (paranoidal check) if (!isset($address[0]) || !$address[0]) { continue; } // setting the language for the current notification modApiFunc('MultiLang', 'setLanguage', @$address[1]); modApiFunc('MultiLang', 'setResourceLanguage', @$address[1]); $format = modApiFunc('Settings', 'getParamValue', 'EMAIL_NOTIFICATION_SETTINGS', 'EMAIL_NOTIFICATION_FORMAT'); $this->prepareEmailTextAndSubject(); // there were some problems with Unix <-> Windows linefeeds // so we make it all Windows style $this->EmailText = str_replace("\n", "\r\n", str_replace("\r\n", "\n", $this->EmailText)); $mail = new ascHtmlMimeMail(); if ($format == "HTML") { $mail->setHtml($this->EmailText); } else { $mail->setText($this->EmailText); } $mail->setSubject($this->EmailSubject); $from = $this->getSendFrom(); $mail->setFrom($from); // $mail->setCc($from); $this->addEmailToTimeline($address[0], $mail->send(array($address[0])), @$address[1]); } // restoting the languages modApiFunc('MultiLang', 'setLanguage', $cur_lng); modApiFunc('MultiLang', 'setResourceLanguage', $cur_res_lng); }