broadcast-message.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Postfix Admin
  4. *
  5. * LICENSE
  6. * This source file is subject to the GPL license that is bundled with
  7. * this package in the file LICENSE.TXT.
  8. *
  9. * Further details on the project are available at http://postfixadmin.sf.net
  10. *
  11. * @version $Id: broadcast-message.php 1781 2015-04-06 22:44:51Z christian_boltz $
  12. * @license GNU GPL v2 or later.
  13. *
  14. * File: broadcast-message.php
  15. * Used to send a message to _ALL_ users with mailboxes on this server.
  16. *
  17. * Template File: broadcast-message.tpl
  18. *
  19. * Template Variables: -none-
  20. *
  21. * Form POST \ GET Variables:
  22. *
  23. * name
  24. * subject
  25. * message
  26. */
  27. require_once('common.php');
  28. authentication_require_role('global-admin');
  29. if ($CONF['sendmail'] != 'YES') {
  30. header("Location: main.php");
  31. exit;
  32. }
  33. $smtp_from_email = smtp_get_admin_email();
  34. if ($_SERVER['REQUEST_METHOD'] == "POST")
  35. {
  36. if (empty($_POST['subject']) || empty($_POST['message']) || empty($_POST['name']))
  37. {
  38. $error = 1;
  39. flash_error($PALANG['pBroadcast_error_empty']);
  40. }
  41. else
  42. {
  43. $table_mailbox = table_by_key('mailbox');
  44. $table_alias = table_by_key('alias');
  45. $q = "select username from $table_mailbox union select goto from $table_alias " .
  46. "where goto not in (select username from $table_mailbox)";
  47. $result = db_query ($q);
  48. if ($result['rows'] > 0)
  49. {
  50. mb_internal_encoding("UTF-8");
  51. $b_name = mb_encode_mimeheader( $_POST['name'], 'UTF-8', 'Q');
  52. $b_subject = mb_encode_mimeheader( $_POST['subject'], 'UTF-8', 'Q');
  53. $b_message = base64_encode($_POST['message']);
  54. $i = 0;
  55. while ($row = db_array ($result['result'])) {
  56. $fTo = $row[0];
  57. $fHeaders = 'To: ' . $fTo . "\n";
  58. $fHeaders .= 'From: ' . $b_name . ' <' . $smtp_from_email . ">\n";
  59. $fHeaders .= 'Subject: ' . $b_subject . "\n";
  60. $fHeaders .= 'MIME-Version: 1.0' . "\n";
  61. $fHeaders .= 'Content-Type: text/plain; charset=UTF-8' . "\n";
  62. $fHeaders .= 'Content-Transfer-Encoding: base64' . "\n";
  63. $fHeaders .= $b_message;
  64. if (!smtp_mail ($fTo, $smtp_from_email, $fHeaders))
  65. {
  66. flash_error(Config::lang_f('pSendmail_result_error', $fTo));
  67. }
  68. else
  69. {
  70. flash_info(Config::lang_f('pSendmail_result_success', $fTo));
  71. }
  72. }
  73. }
  74. flash_info($PALANG['pBroadcast_success']);
  75. $smarty->assign ('smarty_template', 'message');
  76. $smarty->display ('index.tpl');
  77. // echo '<p>'.$PALANG['pBroadcast_success'].'</p>';
  78. }
  79. }
  80. if ($_SERVER['REQUEST_METHOD'] == "GET" || $error == 1)
  81. {
  82. $smarty->assign ('smtp_from_email', $smtp_from_email);
  83. $smarty->assign ('error', $error);
  84. $smarty->assign ('smarty_template', 'broadcast-message');
  85. $smarty->display ('index.tpl');
  86. // include ("templates/broadcast-message.tpl");
  87. }
  88. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  89. ?>