/sys/plugins/classes/mail.class.php
PHP | 87 lines | 46 code | 16 blank | 25 comment | 7 complexity | c57b97b77942be5e1f0f44689ae32aab MD5 | raw file
- <?php
-
- abstract class mail {
-
- /**
- * ???????? ????? ?? ???????
- * @return boolean
- */
- static function queue_process() {
- // ???-?? ??? ??????? ????????? ?????????
- if (cache::get('mail.send_is_process')) {
- return false;
- }
-
-
- $q = mysql_query("SELECT * FROM `mail_queue` LIMIT 10");
- if (!mysql_num_rows($q)) {
- return false;
- }
-
- // ?????? ??????? ?? ?????? ?????? ???????? ??????? ?????????
- cache::set('mail.send_is_process', true, 30);
-
- while ($queue = mysql_fetch_assoc($q)) {
- if (mail::send($queue ['to'], $queue ['title'], $queue ['content'])) {
- mysql_query("DELETE FROM `mail_queue` WHERE `id` = '{$queue['id']}' LIMIT 1");
- }
- }
- // ????????? ?????? ???????? ?????????? ?????????
- cache::set('mail.send_is_process', false);
- return true;
- }
-
- /**
- * ???????? Email ??? ?????????? ? ???????, ???? ????? ?????????
- * @param mixed $toi ??????? ??? ?????? ?????????
- * @param string $title ????????? ?????????
- * @param string $content ?????????? ??????
- * @return boolean
- */
- static function send($toi, $title, $content) {
- // ???? ????????? ????, ?? ?????????? ?????
- if (is_string($toi)) {
- return self::sendOfMail($toi, $title, $content);
- }
-
-
- // ???? ????????? ?????????, ?? ?????? ? ???????
- $toi = (array) $toi;
-
- if (!$toi) {
- return false;
- }
-
- if (function_exists('set_time_limit')) {
- set_time_limit(min(600, max(30, count($toi) / 2)));
- }
- foreach ($toi as $to) {
- mysql_query("INSERT INTO `mail_queue` (`to`, `title`, `content`) VALUES ('" . my_esc($to) . "', '" . my_esc($title) . "', '" . my_esc($content) . "')");
- }
-
-
- return true;
- }
-
- /**
- * ???????????????? ???????? ?????????
- * @global dcms $dcms
- * @param string $to
- * @param string $title
- * @param string $content
- * @return boolean
- */
- static function sendOfMail($to, $title, $content) {
- global $dcms;
- // ???????? ????????? ???????? mail
- $EOL = "\r\n";
- $headers = "From: \"" . $dcms->sitename . "\" <dcms@{$_SERVER['HTTP_HOST']}>$EOL";
- $headers .= "Subject: $title$EOL";
- $headers .= "Mime-Version: 1.0$EOL";
- $headers .= "Content-Type: text/html; charset=\"utf-8\"$EOL";
- return mail($to, '=?utf-8?B?' . base64_encode($title) . '?=', $content, $headers);
- }
-
- }
-
- ?>