diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index f611b14b7f..25165996c7 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -34,9 +34,11 @@ check_login(); if (is_ajax()) { $test_address = get_parameter('test_address', ''); + $params = get_parameter('params', ''); $res = send_test_email( - $test_address + $test_address, + $params ); echo $res; @@ -709,12 +711,25 @@ function perform_email_test () { $('#email_test_failure_message').hide(); var test_address = $('#text-email_test_address').val(); + params = { + email_smtpServer : $('#text-email_smtpServer').val(), + email_smtpPort : $('#text-email_smtpPort').val(), + email_username : $('#text-email_username').val(), + email_password : $('#password-email_password').val(), + email_encryption : $( "#email_encryption option:selected" ).val(), + email_from_dir : $('#text-email_from_dir').val(), + email_from_name : $('#text-email_from_name').val() + }; $.ajax({ type: "POST", url: "ajax.php", - data: "page=godmode/setup/setup_general&test_address="+test_address, - dataType: "html", + data : { + page: "godmode/setup/setup_general", + test_address: test_address, + params: params + }, + dataType: "json", success: function(data) { if (parseInt(data) === 1) { $('#email_test_sent_message').show(); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 20d7422053..e483bebaa8 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -5939,27 +5939,57 @@ function get_data_multiplier($unit) /** * Send test email to check email setups. * - * @param string $to Target email account. + * @param string $to Target email account. + * @param array $params Array with connection data. + * Available fields: + * 'email_smtpServer', + * 'email_smtpPort', + * 'email_username', + * 'email_password', + * 'email_encryption', + * 'email_from_dir', + * 'email_from_name', * * @return integer Status of the email send task. */ function send_test_email( - string $to + string $to, + array $params=null ) { global $config; + $valid_params = [ + 'email_smtpServer', + 'email_smtpPort', + 'email_username', + 'email_password', + 'email_encryption', + 'email_from_dir', + 'email_from_name', + ]; + + if (empty($params) === true) { + foreach ($valid_params as $token) { + $params[$token] = $config[$token]; + } + } else { + if (array_diff($valid_params, array_keys($params)) === false) { + return false; + } + } + $result = false; try { $transport = new Swift_SmtpTransport( - $config['email_smtpServer'], - $config['email_smtpPort'] + $params['email_smtpServer'], + $params['email_smtpPort'] ); - $transport->setUsername($config['email_username']); - $transport->setPassword($config['email_password']); + $transport->setUsername($params['email_username']); + $transport->setPassword($params['email_password']); - if ($config['email_encryption']) { - $transport->setEncryption($config['email_encryption']); + if ($params['email_encryption']) { + $transport->setEncryption($params['email_encryption']); } $mailer = new Swift_Mailer($transport); @@ -5968,8 +5998,8 @@ function send_test_email( $message->setFrom( [ - $config['email_from_dir'] => io_safe_output( - $config['email_from_name'] + $params['email_from_dir'] => io_safe_output( + $params['email_from_name'] ), ] );