Skip to content

Commit c62f68e

Browse files
dpkraneСемисохин Андрей
andauthored
Add email enconding options (#642)
Co-authored-by: Семисохин Андрей <semisohin@kinoplan.ru>
1 parent e31db43 commit c62f68e

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

app/common/includes/daloradius.conf.php.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ $configValues['CONFIG_MAIL_SMTP_SENDER_NAME'] = 'daloRADIUS Mailer';
9898
$configValues['CONFIG_MAIL_SMTP_SUBJECT_PREFIX'] = '[daloRADIUS]';
9999
$configValues['CONFIG_MAIL_SMTP_USERNAME'] = '';
100100
$configValues['CONFIG_MAIL_SMTP_PASSWORD'] = '';
101+
$configValues['CONFIG_MAIL_CHARSET'] = 'utf-8';
101102
$configValues['CONFIG_DASHBOARD_DALO_SECRETKEY'] = 'sillykey';
102103
$configValues['CONFIG_DASHBOARD_DALO_DEBUG'] = '1';
103104
$configValues['CONFIG_DASHBOARD_DALO_DELAYSOFT'] = '5';

app/common/includes/mail.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ function send_email($config_values, $recipient_email_address, $recipient_name, $
7272
$mail->Subject = $subject;
7373
$mail->Body = $body;
7474

75+
// Set email charset
76+
$mail->CharSet = $config_values['CONFIG_MAIL_CHARSET'];
77+
7578
if (is_array($attachment) && array_key_exists('content', $attachment) && array_key_exists('filename', $attachment) ) {
7679
$mail->addStringAttachment($attachment['content'], $attachment['filename'],
77-
PHPMailer\PHPMailer\PHPMailer::ENCODING_BASE64, 'application/pdf', 'attachment');
80+
PHPMailer\PHPMailer\PHPMailer::ENCODING_BASE64, 'text/plain', 'attachment');
7881
}
7982

8083
// Send the email

app/operators/config-mail-settings.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@
149149
$configValues['CONFIG_MAIL_SMTP_PASSWORD'] = "";
150150
}
151151

152+
// validate email charset
153+
if (
154+
array_key_exists('CONFIG_MAIL_CHARSET', $_POST) &&
155+
!empty(trim($_POST['CONFIG_MAIL_CHARSET'])) &&
156+
in_array(strtolower(trim($_POST['CONFIG_MAIL_CHARSET'])), array("utf-8", "iso-8859-1", "us-ascii", "utf-16", "windows-1251", "iso-8859-15", "iso-2022-jp", "shift-jis", "koi8-r", "windows-1252", "iso-8859-5"))
157+
) {
158+
$configValues['CONFIG_MAIL_CHARSET'] = strtolower(trim($_POST['CONFIG_MAIL_CHARSET']));
159+
} else {
160+
$configValues['CONFIG_MAIL_CHARSET'] = "utf-8";
161+
}
162+
152163
// display message
153164
if (count($invalid_input) > 0) {
154165
$failureMsg = sprintf("Invalid input: [%s]", implode(", ", array_values($invalid_input)));
@@ -300,6 +311,16 @@
300311
"tooltipText" => "A prefix for the email subjects",
301312
);
302313

314+
$input_descriptors1[] = array(
315+
"type" => "select",
316+
"options" => array("utf-8", "iso-8859-1", "us-ascii", "utf-16", "windows-1251", "iso-8859-15", "iso-2022-jp", "shift-jis", "koi8-r", "windows-1252", "iso-8859-5"),
317+
"caption" => "Email Character Encoding",
318+
"name" => 'CONFIG_MAIL_CHARSET',
319+
"selected_value" => (!array_key_exists('CONFIG_MAIL_CHARSET', $invalid_input)
320+
? $configValues['CONFIG_MAIL_CHARSET'] : "utf-8"),
321+
"tooltipText" => "Character encoding for outgoing emails",
322+
);
323+
303324

304325
$fieldset1_descriptor = array(
305326
"title" => "Other settings",

0 commit comments

Comments
 (0)