<?php
ob_start();
if(!(is_readable(realpath(dirname(__FILE__).'/../').'/include/includesroutinesservice.inc'))) {
	die('Error - Could not open or read file '.realpath(dirname(__FILE__).'/../').'/include/includesroutinesservice.inc');
} else {
	include_once(realpath(dirname(__FILE__).'/../').'/include/includesroutinesservice.inc');
}

if(!(is_readable(realpath(dirname(__FILE__).'/../').'/include/mail.inc'))) {
	die('Error - Could not open or read file '.realpath(dirname(__FILE__).'/../').'/include/mail.inc');
} else {
	include_once(realpath(dirname(__FILE__).'/../').'/include/mail.inc');
}
if (GetSetting('portal','useRights',0) == 0 || !IsUserLogin() || !isUserAdmin()){
    exit;
}

$cn = db_connect();
$user = db_getUserDataByID($cn, GetUserIDs()[0]);
$lang = db_getLanguageShortByID($cn, $user['user_idlanguageinterface'], true);
$userName = db_getUserNameByID($cn, GetUserIDs()[0]);
$subject = getResourceByLang('email.testmessage.subject', $lang);
if (sendTestEmail($user['user_email'], $subject, $lang, $userName)){
  echo str_replace('%email%', $user['user_email'], getResourceByLang('message.testemailwassentsucceseful', $lang));
} else {
    $msg = getResourceByLang('log.message.errorsend', $lang).' '.$userName.' '.(isset($user) && isset($user['user_email']) ? $user['user_email'] : '');
    logmessage($msg);
    echo $msg;
}
 
db_disconnect($cn);
?>