Fix Port and integrate Hostname Setting on send_email() function. Add Test button to Emails app to test outbound SMTP Settings.

This commit is contained in:
Nate 2019-01-23 14:40:10 -07:00
parent 432052ba26
commit 04b02d5fa5
4 changed files with 281 additions and 4 deletions

View File

@ -481,6 +481,66 @@ $text['header-emails']['ru-ru'] = "Сообщения Электронной П
$text['header-emails']['sv-se'] = "E-post";
$text['header-emails']['uk-ua'] = "";
$text['header-settings']['en-us'] = "Settings";
$text['header-settings']['ar-eg'] = "";
$text['header-settings']['de-at'] = "";
$text['header-settings']['de-ch'] = "";
$text['header-settings']['de-de'] = "";
$text['header-settings']['es-cl'] = "";
$text['header-settings']['es-mx'] = "";
$text['header-settings']['fr-ca'] = "";
$text['header-settings']['fr-fr'] = "";
$text['header-settings']['he-il'] = "";
$text['header-settings']['it-it'] = "";
$text['header-settings']['nl-nl'] = "";
$text['header-settings']['pl-pl'] = "";
$text['header-settings']['pt-br'] = "";
$text['header-settings']['pt-pt'] = "";
$text['header-settings']['ro-ro'] = "";
$text['header-settings']['ru-ru'] = "";
$text['header-settings']['sv-se'] = "";
$text['header-settings']['uk-ua'] = "";
$text['header-connection']['en-us'] = "Connection";
$text['header-connection']['ar-eg'] = "";
$text['header-connection']['de-at'] = "";
$text['header-connection']['de-ch'] = "";
$text['header-connection']['de-de'] = "";
$text['header-connection']['es-cl'] = "";
$text['header-connection']['es-mx'] = "";
$text['header-connection']['fr-ca'] = "";
$text['header-connection']['fr-fr'] = "";
$text['header-connection']['he-il'] = "";
$text['header-connection']['it-it'] = "";
$text['header-connection']['nl-nl'] = "";
$text['header-connection']['pl-pl'] = "";
$text['header-connection']['pt-br'] = "";
$text['header-connection']['pt-pt'] = "";
$text['header-connection']['ro-ro'] = "";
$text['header-connection']['ru-ru'] = "";
$text['header-connection']['sv-se'] = "";
$text['header-connection']['uk-ua'] = "";
$text['header-result']['en-us'] = "Result";
$text['header-result']['ar-eg'] = "";
$text['header-result']['de-at'] = "";
$text['header-result']['de-ch'] = "";
$text['header-result']['de-de'] = "";
$text['header-result']['es-cl'] = "";
$text['header-result']['es-mx'] = "";
$text['header-result']['fr-ca'] = "";
$text['header-result']['fr-fr'] = "";
$text['header-result']['he-il'] = "";
$text['header-result']['it-it'] = "";
$text['header-result']['nl-nl'] = "";
$text['header-result']['pl-pl'] = "";
$text['header-result']['pt-br'] = "";
$text['header-result']['pt-pt'] = "";
$text['header-result']['ro-ro'] = "";
$text['header-result']['ru-ru'] = "";
$text['header-result']['sv-se'] = "";
$text['header-result']['uk-ua'] = "";
$text['description-emails']['en-us'] = "Manage failed email messages.";
$text['description-emails']['ar-eg'] = "";
$text['description-emails']['de-at'] = "Fehlgeschlagene Email-Nachrichten verwalten."; //copied from de-de
@ -501,6 +561,66 @@ $text['description-emails']['ru-ru'] = "Управление ошибочным
$text['description-emails']['sv-se'] = "Hantera misslyckade e-post meddelanden.";
$text['description-emails']['uk-ua'] = "";
$text['button-test']['en-us'] = "Test";
$text['button-test']['ar-eg'] = "";
$text['button-test']['de-at'] = "";
$text['button-test']['de-ch'] = "";
$text['button-test']['de-de'] = "";
$text['button-test']['es-cl'] = "";
$text['button-test']['es-mx'] = "";
$text['button-test']['fr-ca'] = "";
$text['button-test']['fr-fr'] = "";
$text['button-test']['he-il'] = "";
$text['button-test']['it-it'] = "";
$text['button-test']['nl-nl'] = "";
$text['button-test']['pl-pl'] = "";
$text['button-test']['pt-br'] = "";
$text['button-test']['pt-pt'] = "";
$text['button-test']['ro-ro'] = "";
$text['button-test']['ru-ru'] = "";
$text['button-test']['sv-se'] = "";
$text['button-test']['uk-ua'] = "";
$text['button-send']['en-us'] = "Send";
$text['button-send']['ar-eg'] = "";
$text['button-send']['de-at'] = "";
$text['button-send']['de-ch'] = "";
$text['button-send']['de-de'] = "";
$text['button-send']['es-cl'] = "";
$text['button-send']['es-mx'] = "";
$text['button-send']['fr-ca'] = "";
$text['button-send']['fr-fr'] = "";
$text['button-send']['he-il'] = "";
$text['button-send']['it-it'] = "";
$text['button-send']['nl-nl'] = "";
$text['button-send']['pl-pl'] = "";
$text['button-send']['pt-br'] = "";
$text['button-send']['pt-pt'] = "";
$text['button-send']['ro-ro'] = "";
$text['button-send']['ru-ru'] = "";
$text['button-send']['sv-se'] = "";
$text['button-send']['uk-ua'] = "";
$text['button-close']['en-us'] = "Close";
$text['button-close']['ar-eg'] = "";
$text['button-close']['de-at'] = "";
$text['button-close']['de-ch'] = "";
$text['button-close']['de-de'] = "";
$text['button-close']['es-cl'] = "";
$text['button-close']['es-mx'] = "";
$text['button-close']['fr-ca'] = "";
$text['button-close']['fr-fr'] = "";
$text['button-close']['he-il'] = "";
$text['button-close']['it-it'] = "";
$text['button-close']['nl-nl'] = "";
$text['button-close']['pl-pl'] = "";
$text['button-close']['pt-br'] = "";
$text['button-close']['pt-pt'] = "";
$text['button-close']['ro-ro'] = "";
$text['button-close']['ru-ru'] = "";
$text['button-close']['sv-se'] = "";
$text['button-close']['uk-ua'] = "";
$text['button-resend']['en-us'] = "Resend";
$text['button-resend']['ar-eg'] = "";
$text['button-resend']['de-at'] = "Erneut senden"; //copied from de-de

67
app/emails/email_test.php Normal file
View File

@ -0,0 +1,67 @@
<?php
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
if (!permission_exists('email_view')) {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
if (valid_email($_POST['to'])) {
$recipient = check_str($_POST['to']);
echo "<b>".$text['header-settings']."</b>\n";
echo "<br><br>\n";
ksort($_SESSION['email']);
foreach ($_SESSION['email'] as $name => $setting) {
foreach ($setting as $type => $value) {
if ($type == 'uuid') { $uuid = $value; continue; }
if ($name == 'smtp_password') { $value = '[REDACTED]'; }
if (permission_exists('default_setting_edit')) {
echo "<a href='../../core/default_settings/default_setting_edit.php?id=".$uuid."' target='_blank'>".$name.'</a>: '.$value."<br>\n";
}
else {
echo $name.': '.$value."<br>\n";
}
}
}
echo "<br><br>\n";
echo "<b>".$text['header-connection']."</b>\n";
echo "<br><br>\n";
$eml_body = "<b>Test Message</b><br /><br />\n";
$eml_body .= "This message is a test of the SMTP settings configured within your PBX.<br />\n";
$eml_body .= "If you received this message, your current SMTP settings are valid.<br /><br />\n";
ob_start();
$sent = !send_email($recipient, 'Test Message', $eml_body, $eml_error) ? false : true;
$response = ob_get_clean();
echo $response;
echo "<br><br>\n";
echo "<b>".$text['header-result']."</b>\n";
echo "<br><br>\n";
echo $sent ? "Message Sent Successfully<br>Receipient: <a href='mailto:".$recipient."'>".$recipient."</a>" : "Message Failed...<br>".$eml_error;
}
else {
echo "Error: Invalid Recipient Address";
}
echo "<br>\n";
echo "<center>\n";
echo " <input type='button' class='btn' style='margin-top: 15px;' value='".$text['button-close']."' onclick=\"$('#test_result_layer').fadeOut(200);\">\n";
echo "</center>\n";
?>

View File

@ -110,7 +110,52 @@ else {
require_once "resources/header.php";
require_once "resources/paging.php";
//styles
echo "<style>\n";
echo " #test_result_layer {\n";
echo " z-index: 999999;\n";
echo " position: absolute;\n";
echo " left: 0px;\n";
echo " top: 0px;\n";
echo " right: 0px;\n";
echo " bottom: 0px;\n";
echo " text-align: center;\n";
echo " vertical-align: middle;\n";
echo " }\n";
echo " #test_result_container {\n";
echo " display: block;\n";
echo " overflow: auto;\n";
echo " background-color: #fff;\n";
echo " padding: 20px 30px;\n";
if (http_user_agent('mobile')) {
echo " margin: 0;\n";
}
else {
echo " margin: auto 10%;\n";
}
echo " text-align: left;\n";
echo " -webkit-box-shadow: 0px 1px 20px #888;\n";
echo " -moz-box-shadow: 0px 1px 20px #888;\n";
echo " box-shadow: 0px 1px 20px #888;\n";
echo " }\n";
echo "</style>\n";
//test result layer
echo "<div id='test_result_layer' style='display: none;'>\n";
echo " <table cellpadding='0' cellspacing='0' border='0' width='100%' height='100%'>\n";
echo " <tr>\n";
echo " <td align='center' valign='middle'>\n";
echo " <span id='test_result_container'></span>\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</div>\n";
//show the content
echo "<form id='test_form' method='post' action='email_test.php' target='_blank'>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td width='50%' align='left' valign='top' nowrap='nowrap'>";
@ -119,6 +164,11 @@ else {
echo " ".$text['description-emails'];
echo " </td>\n";
echo " <td width='50%' align='right' valign='top'>\n";
echo " <input type='button' class='btn' id='test_button' alt=\"".$text['button-test']."\" onclick=\"$(this).fadeOut(400, function(){ $('span#test_form').fadeIn(400); $('#to').focus(); });\" value='".$text['button-test']."'>\n";
echo " <span id='test_form' style='display: none;'>\n";
echo " <input type='text' class='formfld' style='min-width: 150px; width:150px; max-width: 150px;' name='to' id='to' placeholder='recipient@domain.com'>\n";
echo " <input type='submit' class='btn' id='send_button' alt=\"".$text['button-send']."\" value='".$text['button-send']."'>\n";
echo " </span>\n";
if (permission_exists('emails_all')) {
if ($_REQUEST['showall'] != 'true') {
echo " <input type='button' class='btn' value='".$text['button-show_all']."' onclick=\"window.location='emails.php?showall=true';\">\n";
@ -128,6 +178,7 @@ else {
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "</form>\n";
echo "<br />\n";
//prepare to page the results
@ -264,6 +315,30 @@ else {
echo "</table>";
echo "<br /><br />";
//test script
echo "<script>\n";
echo " $('#test_form').submit(function(event) {\n";
echo " event.preventDefault();\n";
echo " $.ajax({\n";
echo " url: $(this).attr('action'),\n";
echo " type: $(this).attr('method'),\n";
echo " data: new FormData(this),\n";
echo " processData: false,\n";
echo " contentType: false,\n";
echo " cache: false,\n";
echo " success: function(response){\n";
echo " $('#test_result_container').html(response);\n";
echo " $('#test_result_layer').fadeIn(400);\n";
echo " $('span#test_form').fadeOut(400);\n";
echo " $('#test_button').fadeIn(400);\n";
echo " $('#to').val('');\n";
echo " }\n";
echo " });\n";
echo " });\n";
echo "</script>\n";
//include the footer
require_once "resources/footer.php";
?>

View File

@ -1446,23 +1446,37 @@ function number_pad($number,$n) {
$mail = new PHPMailer();
$mail -> IsSMTP();
if ($_SESSION['email']['smtp_hostname']['text'] != '') {
$mail -> Hostname = $_SESSION['email']['smtp_hostname']['text'];
}
$mail -> Host = $_SESSION['email']['smtp_host']['text'];
if ($_SESSION['email']['smtp_port']['text'] != '') {
$mail -> Port = $_SESSION['email']['smtp_port']['text'];
if (is_numeric($_SESSION['email']['smtp_port']['numeric'])) {
$mail -> Port = $_SESSION['email']['smtp_port']['numeric'];
}
if ($_SESSION['email']['smtp_auth']['text'] == "true") {
$mail -> SMTPAuth = $_SESSION['email']['smtp_auth']['text'];
}
if ($_SESSION['email']['smtp_username']['text']) {
$mail -> Username = $_SESSION['email']['smtp_username']['text'];
$mail -> Password = $_SESSION['email']['smtp_password']['text'];
}
else {
$mail -> SMTPAuth = 'false';
}
if ($_SESSION['email']['smtp_secure']['text'] == "none") {
$_SESSION['email']['smtp_secure']['text'] = '';
}
if ($_SESSION['email']['smtp_secure']['text'] != '') {
$mail -> SMTPSecure = $_SESSION['email']['smtp_secure']['text'];
}
if (isset($_SESSION['email']['smtp_validate_certificate']) && $_SESSION['email']['smtp_validate_certificate']['boolean'] == "false") {
// bypass TLS certificate check e.g. for self-signed certificates
$mail -> SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
}
$eml_from_address = ($eml_from_address != '') ? $eml_from_address : $_SESSION['email']['smtp_from']['text'];
$eml_from_name = ($eml_from_name != '') ? $eml_from_name : $_SESSION['email']['smtp_from_name']['text'];
$mail -> SetFrom($eml_from_address, $eml_from_name);
@ -1470,6 +1484,7 @@ function number_pad($number,$n) {
$mail -> Subject = $eml_subject;
$mail -> MsgHTML($eml_body);
$mail -> Priority = $eml_priority;
$mail -> SMTPDebug = 3;
$address_found = false;