email_tester.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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('E-mail tester');
  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('Send message'), 'submit', false, ['cols-size' => [2, 8, 2]]);
  29. $errorsInfo = MessageManager::failedSentMailErrors();
  30. if ($form->validate()) {
  31. $values = $form->exportValues();
  32. $user = api_get_user_entity(api_get_user_id());
  33. $mailIsSent = api_mail_html(
  34. get_lang('User testing of e-mail configuration'),
  35. $values['destination'],
  36. $values['subject'],
  37. $values['content'],
  38. UserManager::formatUserFullName($user),
  39. $user->getEmail()
  40. );
  41. Display::addFlash(
  42. Display::return_message(get_lang('E-mail sent. This procedure works in all aspects similarly to the normal e-mail sending of Chamilo, but allows for more flexibility in terms of destination e-mail and message body.'), 'success')
  43. );
  44. header('Location: '.api_get_self());
  45. exit;
  46. }
  47. $view = new Template($toolName);
  48. $view->assign('form', $form->returnForm());
  49. $view->assign('errors', $errorsInfo);
  50. $template = $view->get_template('admin/email_tester.tpl');
  51. $content = $view->fetch($template);
  52. $view->assign('header', $toolName);
  53. $view->assign('content', $content);
  54. $view->display_one_col_template();