Email test working with data in text fields
This commit is contained in:
parent
d87c9e0cc1
commit
6ad371e4ab
|
@ -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;
|
||||
|
@ -704,12 +706,25 @@ function show_email_test(id) {
|
|||
|
||||
function perform_email_test () {
|
||||
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();
|
||||
|
|
|
@ -5960,27 +5960,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);
|
||||
|
@ -5989,8 +6019,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']
|
||||
),
|
||||
]
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue