mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
fixed email test
This commit is contained in:
parent
d8daf9f063
commit
2915a3bd35
@ -59,18 +59,10 @@ global $config;
|
|||||||
check_login();
|
check_login();
|
||||||
|
|
||||||
if (is_ajax()) {
|
if (is_ajax()) {
|
||||||
enterprise_include_once('include/functions_cron.php');
|
|
||||||
|
|
||||||
$test_address = get_parameter('test_address', '');
|
$test_address = get_parameter('test_address', '');
|
||||||
|
|
||||||
$res = enterprise_hook(
|
$res = send_test_email(
|
||||||
'send_email_attachment',
|
$test_address
|
||||||
[
|
|
||||||
$test_address,
|
|
||||||
__('This is an email test sent from Pandora FMS. If you can read this, your configuration works.'),
|
|
||||||
__('Testing Pandora FMS email'),
|
|
||||||
null,
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
echo $res;
|
echo $res;
|
||||||
@ -469,7 +461,6 @@ function show_email_test(id) {
|
|||||||
resizable: true,
|
resizable: true,
|
||||||
draggable: true,
|
draggable: true,
|
||||||
modal: true,
|
modal: true,
|
||||||
height: 175,
|
|
||||||
width: 450,
|
width: 450,
|
||||||
overlay: {
|
overlay: {
|
||||||
opacity: 0.5,
|
opacity: 0.5,
|
||||||
@ -487,7 +478,11 @@ function perform_email_test () {
|
|||||||
data: "page=godmode/setup/setup_general&test_address="+test_address,
|
data: "page=godmode/setup/setup_general&test_address="+test_address,
|
||||||
dataType: "html",
|
dataType: "html",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$('#email_test_sent_message').show();
|
if (parseInt(data) === 1) {
|
||||||
|
$('#email_test_sent_message').show();
|
||||||
|
} else {
|
||||||
|
$('#email_test_failure_message').show();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function() {
|
||||||
$('#email_test_failure_message').show();
|
$('#email_test_failure_message').show();
|
||||||
|
@ -5735,3 +5735,60 @@ function get_data_multiplier($unit)
|
|||||||
|
|
||||||
return $multiplier;
|
return $multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send test email to check email setups.
|
||||||
|
*
|
||||||
|
* @param string $to Target email account.
|
||||||
|
*
|
||||||
|
* @return integer Status of the email send task.
|
||||||
|
*/
|
||||||
|
function send_test_email(
|
||||||
|
string $to
|
||||||
|
) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$result = false;
|
||||||
|
try {
|
||||||
|
$transport = new Swift_SmtpTransport(
|
||||||
|
$config['email_smtpServer'],
|
||||||
|
$config['email_smtpPort']
|
||||||
|
);
|
||||||
|
|
||||||
|
$transport->setUsername($config['email_username']);
|
||||||
|
$transport->setPassword($config['email_password']);
|
||||||
|
|
||||||
|
if ($config['email_encryption']) {
|
||||||
|
$transport->setEncryption($config['email_encryption']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mailer = new Swift_Mailer($transport);
|
||||||
|
|
||||||
|
$message = new Swift_Message(io_safe_output(__('Testing Pandora FMS email')));
|
||||||
|
|
||||||
|
$message->setFrom(
|
||||||
|
[
|
||||||
|
$config['email_from_dir'] => io_safe_output(
|
||||||
|
$config['email_from_name']
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$to = trim($to);
|
||||||
|
$message->setTo([$to => $to]);
|
||||||
|
$message->setBody(
|
||||||
|
__('This is an email test sent from Pandora FMS. If you can read this, your configuration works.'),
|
||||||
|
'text/html'
|
||||||
|
);
|
||||||
|
|
||||||
|
ini_restore('sendmail_from');
|
||||||
|
|
||||||
|
$result = $mailer->send($message);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log($e->getMessage());
|
||||||
|
db_pandora_audit('Cron jobs mail', $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user