email_test.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /*-
  3. * Copyright (c) 2008-2023 Mark J Crane <[email protected]>
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  18. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. * SUCH DAMAGE.
  25. */
  26. //includes files
  27. require_once dirname(__DIR__, 2) . "/resources/require.php";
  28. require_once "resources/check_auth.php";
  29. //check permissions
  30. if (!permission_exists('email_queue_view')) {
  31. echo "access denied";
  32. exit;
  33. }
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //prepare the email
  38. $email_recipient = !empty($_POST['to']) && valid_email($_POST['to']) ? strtolower($_POST['to']) : null;
  39. $email_body = "<b>Test Message</b><br /><br />\n";
  40. $email_body .= "This message is a test of the SMTP settings configured within your PBX.<br />\n";
  41. $email_body .= "If you received this message, your current SMTP settings are valid.<br /><br />\n";
  42. $email_from_address = $_SESSION['email']['smtp_from']['text'];
  43. $email_from_name = $_SESSION['email']['smtp_from_name']['text'];
  44. //send email
  45. $sent = 0;
  46. $email = new email;
  47. $email->recipients = $email_recipient;
  48. $email->subject = 'Test Message';
  49. $email->body = $email_body;
  50. $email->from_address = $email_from_address;
  51. $email->from_name = $email_from_name;
  52. $email->attachments = $email_attachments ?? null;
  53. $email->debug_level = 3;
  54. $email->method = 'direct';
  55. ob_start();
  56. $sent = $email->send();
  57. $send_response = ob_get_contents();
  58. ob_end_clean();
  59. $end_response = $email->response;
  60. //format response
  61. $email_response = array_merge(explode("\n", str_replace('<br>', '', $end_response)), explode("<br>\n", $send_response));
  62. if (!empty($email_response) && is_array($email_response) && @sizeof($email_response) != 0) {
  63. foreach ($email_response as $x => $line) {
  64. if (empty(trim($line))) { unset($email_response[$x]); }
  65. }
  66. }
  67. //show the content
  68. echo "<input type='button' class='btn' style='float: right;' value='".$text['button-close']."' onclick=\"$('#test_result_layer').fadeOut(200);\">\n";
  69. echo "<b>".$text['header-email_test']."</b>\n";
  70. echo "<br><br>\n";
  71. echo $text['description-email_test']."\n";
  72. echo "<br><br><br>\n";
  73. echo "<b>".$text['header-settings']."</b>\n";
  74. echo "<br><br>\n";
  75. ksort($_SESSION['email']);
  76. echo "<table>\n";
  77. foreach ($_SESSION['email'] as $name => $setting) {
  78. foreach ($setting as $type => $value) {
  79. echo "<tr>\n";
  80. if ($type == 'uuid') { $uuid = $value; continue; }
  81. if ($name == 'smtp_password') { $value = str_repeat('*', strlen($value)); }
  82. if (permission_exists('default_setting_edit')) {
  83. echo "<td style='padding-right: 30px;'><a href='../../core/default_settings/default_setting_edit.php?id=".$uuid."' target='_blank'>".$name."</a></td>\n";
  84. echo "<td style='padding-right: 30px;'>".$value."</td>\n";
  85. }
  86. else {
  87. echo "<td style='padding-right: 30px;'>".$name."</td>\n";
  88. echo "<td style='padding-right: 30px;'>".$value."</td>\n";
  89. }
  90. echo "<tr>\n";
  91. }
  92. }
  93. echo "</table>\n";
  94. echo "<br><br>\n";
  95. echo "<b>".$text['header-connection']."</b>\n";
  96. echo "<br><br>\n";
  97. echo "<div style='width: 100%; max-height: 250px; overflow: auto; border: 1px solid ".($_SESSION['theme']['table_row_border_color']['text'] ?? '#c5d1e5')."; padding: 12px 15px; background-color: ".($_SESSION['theme']['table_row_background_color_light']['text'] ?? '#fff')."; font-family: monospace; font-size: 85%;'>\n";
  98. if (!empty($email_response) && is_array($email_response) && @sizeof($email_response) != 0) {
  99. echo implode("<br>\n<hr style='margin: 3px 0;'>\n", $email_response);
  100. }
  101. echo "</div>\n";
  102. echo "<br><br>\n";
  103. echo "<b>".$text['header-result']."</b>\n";
  104. echo "<br><br>\n";
  105. echo $sent ? "Message Sent Successfully<br>Receipient: <a href='mailto:".$email_recipient."'>".$email_recipient."</a>" : "Message Failed";
  106. echo "<br><br>\n";
  107. echo "<center>\n";
  108. echo " <input type='button' class='btn' style='margin-top: 15px;' value='".$text['button-close']."' onclick=\"$('#test_result_layer').fadeOut(200);\">\n";
  109. echo "</center>\n";
  110. ?>