email_tester.php 2.0 KB

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