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.

broadcast-message.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 1842 2016-05-20 20:42:04Z 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 (safepost('token') != $_SESSION['PFA_token']) die('Invalid token!');
  37. if (empty($_POST['subject']) || empty($_POST['message']) || empty($_POST['name']))
  38. {
  39. $error = 1;
  40. flash_error($PALANG['pBroadcast_error_empty']);
  41. }
  42. else
  43. {
  44. $table_mailbox = table_by_key('mailbox');
  45. $table_alias = table_by_key('alias');
  46. $q = "select username from $table_mailbox union select goto from $table_alias " .
  47. "where goto not in (select username from $table_mailbox)";
  48. $result = db_query ($q);
  49. if ($result['rows'] > 0)
  50. {
  51. mb_internal_encoding("UTF-8");
  52. $b_name = mb_encode_mimeheader( $_POST['name'], 'UTF-8', 'Q');
  53. $b_subject = mb_encode_mimeheader( $_POST['subject'], 'UTF-8', 'Q');
  54. $b_message = base64_encode($_POST['message']);
  55. $i = 0;
  56. while ($row = db_array ($result['result'])) {
  57. $fTo = $row[0];
  58. $fHeaders = 'To: ' . $fTo . "\n";
  59. $fHeaders .= 'From: ' . $b_name . ' <' . $smtp_from_email . ">\n";
  60. $fHeaders .= 'Subject: ' . $b_subject . "\n";
  61. $fHeaders .= 'MIME-Version: 1.0' . "\n";
  62. $fHeaders .= 'Content-Type: text/plain; charset=UTF-8' . "\n";
  63. $fHeaders .= 'Content-Transfer-Encoding: base64' . "\n";
  64. $fHeaders .= $b_message;
  65. if (!smtp_mail ($fTo, $smtp_from_email, $fHeaders))
  66. {
  67. flash_error(Config::lang_f('pSendmail_result_error', $fTo));
  68. }
  69. else
  70. {
  71. flash_info(Config::lang_f('pSendmail_result_success', $fTo));
  72. }
  73. }
  74. }
  75. flash_info($PALANG['pBroadcast_success']);
  76. $smarty->assign ('smarty_template', 'message');
  77. $smarty->display ('index.tpl');
  78. // echo '<p>'.$PALANG['pBroadcast_success'].'</p>';
  79. }
  80. }
  81. if ($_SERVER['REQUEST_METHOD'] == "GET" || $error == 1)
  82. {
  83. $smarty->assign ('smtp_from_email', $smtp_from_email);
  84. $smarty->assign ('error', $error);
  85. $smarty->assign ('smarty_template', 'broadcast-message');
  86. $smarty->display ('index.tpl');
  87. // include ("templates/broadcast-message.tpl");
  88. }
  89. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  90. ?>