diff --git a/api.php b/api.php index db1f04b..a34ca73 100644 --- a/api.php +++ b/api.php @@ -305,16 +305,22 @@ class ZammadClient { /** Lähetä vastaus tikettiin */ public function createArticle(int $ticketId, string $body, string $to = '', string $subject = '', string $type = 'email'): array { + // Muunna plain-text HTML:ksi jos body ei sisällä HTML-tageja + $htmlBody = $body; + if (strip_tags($body) === $body) { + $htmlBody = nl2br(htmlspecialchars($body, ENT_QUOTES, 'UTF-8')); + } $data = [ 'ticket_id' => $ticketId, - 'body' => $body, + 'body' => $htmlBody, 'content_type' => 'text/html', 'type' => $type, + 'subtype' => 'reply', 'internal' => false, 'sender' => 'Agent', ]; if ($to) $data['to'] = $to; - if ($subject) $data['subject'] = $subject; + if ($subject) $data['subject'] = 'Re: ' . preg_replace('/^Re:\s*/i', '', $subject); return $this->request('POST', 'ticket_articles', $data); }