email_tester.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Index page of the admin tools.
  5. *
  6. * @package chamilo.admin
  7. */
  8. // Resetting the course id.
  9. $cidReset = true;
  10. // Including some necessary chamilo files.
  11. require_once __DIR__.'/../inc/global.inc.php';
  12. api_protect_admin_script();
  13. // Setting the section (for the tabs).
  14. $this_section = SECTION_PLATFORM_ADMIN;
  15. $toolName = get_lang('EMailTester');
  16. $form = new FormValidator('email_tester');
  17. $form->addText('smtp_host', get_lang('Host'), false, ['cols-size' => [2, 8, 2]]);
  18. $form->addText('smtp_port', get_lang('Port'), false, ['cols-size' => [2, 8, 2]]);
  19. $form->addText('destination', get_lang('Destination'), true, ['cols-size' => [2, 8, 2]]);
  20. $form->addText('subject', get_lang('Subject'), true, ['cols-size' => [2, 8, 2]]);
  21. $form->addHtmlEditor(
  22. 'content',
  23. get_lang('Message'),
  24. true,
  25. false,
  26. ['ToolbarSet' => 'Minimal', 'cols-size' => [2, 8, 2]]
  27. );
  28. $form->addButtonSend(get_lang('SendMessage'), 'submit', false, ['cols-size' => [2, 8, 2]]);
  29. $form->setDefaults([
  30. 'smtp_host' => $platform_email['SMTP_HOST'],
  31. 'smtp_port' => $platform_email['SMTP_PORT'],
  32. ]);
  33. $form->freeze(['smtp_host', 'smtp_port']);
  34. $errorsInfo = MessageManager::failedSentMailErrors();
  35. if ($form->validate()) {
  36. $values = $form->exportValues();
  37. $user = api_get_user_entity(api_get_user_id());
  38. $mailIsSent = api_mail_html(
  39. get_lang('UserTestingEMailConf'),
  40. $values['destination'],
  41. $values['subject'],
  42. $values['content'],
  43. UserManager::formatUserFullName($user),
  44. $user->getEmail()
  45. );
  46. Display::addFlash(
  47. Display::return_message(get_lang('MailingTestSent'), 'success')
  48. );
  49. header('Location: '.api_get_self());
  50. exit;
  51. }
  52. $view = new Template($toolName);
  53. $view->assign('form', $form->returnForm());
  54. $view->assign('errors', $errorsInfo);
  55. $template = $view->get_template('admin/email_tester.tpl');
  56. $content = $view->fetch($template);
  57. $view->assign('header', $toolName);
  58. $view->assign('content', $content);
  59. $view->display_one_col_template();