diff --git a/api.php b/api.php
index 505e160..373fc48 100644
--- a/api.php
+++ b/api.php
@@ -2075,6 +2075,7 @@ switch ($action) {
$id = $input['id'] ?? '';
$body = trim($input['body'] ?? '');
$replyMailboxId = $input['mailbox_id'] ?? '';
+ $replyTo = trim($input['to'] ?? '');
$replyCc = trim($input['cc'] ?? '');
if (empty($body)) {
http_response_code(400);
@@ -2124,7 +2125,8 @@ switch ($action) {
$ccToSend = $replyCc !== '' ? $replyCc : ($t['cc'] ?? '');
$subject = 'Re: ' . $t['subject'];
- $sent = sendTicketMail($t['from_email'], $subject, $emailBody, $lastMsgId, trim($allRefs), $replyMailbox, $ccToSend);
+ $toAddress = $replyTo !== '' ? $replyTo : $t['from_email'];
+ $sent = sendTicketMail($toAddress, $subject, $emailBody, $lastMsgId, trim($allRefs), $replyMailbox, $ccToSend);
if (!$sent) {
http_response_code(500);
diff --git a/index.html b/index.html
index 813b355..28b0c79 100644
--- a/index.html
+++ b/index.html
@@ -452,6 +452,10 @@
+
+
+
+
diff --git a/script.js b/script.js
index e9a858d..b120d9c 100644
--- a/script.js
+++ b/script.js
@@ -1579,6 +1579,10 @@ async function showTicketDetail(id, companyId = '') {
document.querySelector('.btn-reply-tab[data-reply-type="reply"]').classList.add('active');
document.getElementById('btn-send-reply').textContent = 'Lähetä vastaus';
+ // TO-kenttä — tiketin alkuperäinen lähettäjä
+ const toField = document.getElementById('reply-to');
+ if (toField) toField.value = ticket.from_email || '';
+
// CC-kenttä — täytetään tiketin CC:stä
const ccField = document.getElementById('reply-cc');
if (ccField) ccField.value = ticket.cc || '';
@@ -1709,9 +1713,11 @@ document.getElementById('btn-send-reply').addEventListener('click', async () =>
const payload = { id: currentTicketId, body };
if (ticketReplyType !== 'note') {
const mbSel = document.getElementById('reply-mailbox-select');
+ const toFld = document.getElementById('reply-to');
const ccFld = document.getElementById('reply-cc');
const useSig = document.getElementById('reply-use-signature');
if (mbSel) payload.mailbox_id = mbSel.value;
+ if (toFld && toFld.value.trim()) payload.to = toFld.value.trim();
if (ccFld) payload.cc = ccFld.value.trim();
if (useSig && !useSig.checked) payload.no_signature = true;
}