PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/sys/plugins/classes/mail.class.php

https://bitbucket.org/DESURE/dcms
PHP | 87 lines | 46 code | 16 blank | 25 comment | 7 complexity | c57b97b77942be5e1f0f44689ae32aab MD5 | raw file
  1. <?php
  2. abstract class mail {
  3. /**
  4. * ???????? ????? ?? ???????
  5. * @return boolean
  6. */
  7. static function queue_process() {
  8. // ???-?? ??? ??????? ????????? ?????????
  9. if (cache::get('mail.send_is_process')) {
  10. return false;
  11. }
  12. $q = mysql_query("SELECT * FROM `mail_queue` LIMIT 10");
  13. if (!mysql_num_rows($q)) {
  14. return false;
  15. }
  16. // ?????? ??????? ?? ?????? ?????? ???????? ??????? ?????????
  17. cache::set('mail.send_is_process', true, 30);
  18. while ($queue = mysql_fetch_assoc($q)) {
  19. if (mail::send($queue ['to'], $queue ['title'], $queue ['content'])) {
  20. mysql_query("DELETE FROM `mail_queue` WHERE `id` = '{$queue['id']}' LIMIT 1");
  21. }
  22. }
  23. // ????????? ?????? ???????? ?????????? ?????????
  24. cache::set('mail.send_is_process', false);
  25. return true;
  26. }
  27. /**
  28. * ???????? Email ??? ?????????? ? ???????, ???? ????? ?????????
  29. * @param mixed $toi ??????? ??? ?????? ?????????
  30. * @param string $title ????????? ?????????
  31. * @param string $content ?????????? ??????
  32. * @return boolean
  33. */
  34. static function send($toi, $title, $content) {
  35. // ???? ????????? ????, ?? ?????????? ?????
  36. if (is_string($toi)) {
  37. return self::sendOfMail($toi, $title, $content);
  38. }
  39. // ???? ????????? ?????????, ?? ?????? ? ???????
  40. $toi = (array) $toi;
  41. if (!$toi) {
  42. return false;
  43. }
  44. if (function_exists('set_time_limit')) {
  45. set_time_limit(min(600, max(30, count($toi) / 2)));
  46. }
  47. foreach ($toi as $to) {
  48. mysql_query("INSERT INTO `mail_queue` (`to`, `title`, `content`) VALUES ('" . my_esc($to) . "', '" . my_esc($title) . "', '" . my_esc($content) . "')");
  49. }
  50. return true;
  51. }
  52. /**
  53. * ???????????????? ???????? ?????????
  54. * @global dcms $dcms
  55. * @param string $to
  56. * @param string $title
  57. * @param string $content
  58. * @return boolean
  59. */
  60. static function sendOfMail($to, $title, $content) {
  61. global $dcms;
  62. // ???????? ????????? ???????? mail
  63. $EOL = "\r\n";
  64. $headers = "From: \"" . $dcms->sitename . "\" <dcms@{$_SERVER['HTTP_HOST']}>$EOL";
  65. $headers .= "Subject: $title$EOL";
  66. $headers .= "Mime-Version: 1.0$EOL";
  67. $headers .= "Content-Type: text/html; charset=\"utf-8\"$EOL";
  68. return mail($to, '=?utf-8?B?' . base64_encode($title) . '?=', $content, $headers);
  69. }
  70. }
  71. ?>