PostfixAdmin - web based virtual user administration interface for Postfix mail servers https://postfixadmin.github.io/postfixadmin/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.7 KiB

  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 :
  10. * http://www.postfixadmin.com or http://postfixadmin.sf.net
  11. *
  12. * @version $Id$
  13. * @license GNU GPL v2 or later.
  14. *
  15. * File: broadcast-message.php
  16. * Used to send a message to _ALL_ users with mailboxes on this server.
  17. *
  18. * Template File: broadcast-message.php
  19. *
  20. * Template Variables: -none-
  21. *
  22. * Form POST \ GET Variables:
  23. *
  24. * name
  25. * subject
  26. * message
  27. */
  28. require_once('common.php');
  29. authentication_require_role('global-admin');
  30. if ($CONF['sendmail'] != 'YES') {
  31. header("Location: " . $CONF['postfix_admin_url'] . "/main.php");
  32. exit;
  33. }
  34. $SESSID_USERNAME = authentication_get_username();
  35. if ($_SERVER['REQUEST_METHOD'] == "POST")
  36. {
  37. if (empty($_POST['subject']) || empty($_POST['message']) || empty($_POST['name']))
  38. {
  39. $error = 1;
  40. }
  41. else
  42. {
  43. $q = 'select username from mailbox union '.
  44. 'select goto from alias '.
  45. 'where goto not in (select username from mailbox)';
  46. $result = db_query ($q);
  47. if ($result['rows'] > 0)
  48. {
  49. $b_name = mb_encode_mimeheader( $_POST['name'], 'UTF-8', 'Q');
  50. $b_subject = mb_encode_mimeheader( $_POST['subject'], 'UTF-8', 'Q');
  51. $b_message = base64_encode($_POST['message']);
  52. $i = 0;
  53. while ($row = db_array ($result['result'])) {
  54. $fTo = $row[0];
  55. $fHeaders = 'To: ' . $fTo . "\n";
  56. $fHeaders .= 'From: ' . $b_name . ' <' . $CONF['admin_email'] . ">\n";
  57. $fHeaders .= 'Subject: ' . $b_subject . "\n";
  58. $fHeaders .= 'MIME-Version: 1.0' . "\n";
  59. $fHeaders .= 'Content-Type: text/plain; charset=UTF-8' . "\n";
  60. $fHeaders .= 'Content-Transfer-Encoding: base64' . "\n";
  61. $fHeaders .= $b_message;
  62. if (!smtp_mail ($fTo, $CONF['admin_email'], $fHeaders))
  63. {
  64. $tMessage .= "<br />" . $PALANG['pSendmail_result_error'] . "<br />";
  65. }
  66. else
  67. {
  68. $tMessage .= "<br />" . $PALANG['pSendmail_result_success'] . "<br />";
  69. }
  70. }
  71. }
  72. include ("templates/header.php");
  73. include ("templates/menu.php");
  74. echo '<p>'.$PALANG['pBroadcast_success'].'</p>';
  75. include ("templates/footer.php");
  76. }
  77. }
  78. if ($_SERVER['REQUEST_METHOD'] == "GET" || $error == 1)
  79. {
  80. include ("templates/header.php");
  81. include ("templates/menu.php");
  82. include ("templates/broadcast-message.php");
  83. include ("templates/footer.php");
  84. }
  85. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  86. ?>