Korjaa Zammad-vastauksen sähköpostilähetys

Lisätty subtype: 'reply' Zammad-artikkelin luontiin — ilman tätä
Zammad luo artikkelin mutta ei lähetä sähköpostia vastaanottajalle.
Myös plain-text muunnetaan HTML:ksi ja subject saa Re: -etuliitteen.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-13 01:51:35 +02:00
parent c4e7f45bca
commit 6e0596959b

10
api.php
View File

@@ -305,16 +305,22 @@ class ZammadClient {
/** Lähetä vastaus tikettiin */ /** Lähetä vastaus tikettiin */
public function createArticle(int $ticketId, string $body, string $to = '', string $subject = '', string $type = 'email'): array { 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 = [ $data = [
'ticket_id' => $ticketId, 'ticket_id' => $ticketId,
'body' => $body, 'body' => $htmlBody,
'content_type' => 'text/html', 'content_type' => 'text/html',
'type' => $type, 'type' => $type,
'subtype' => 'reply',
'internal' => false, 'internal' => false,
'sender' => 'Agent', 'sender' => 'Agent',
]; ];
if ($to) $data['to'] = $to; 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); return $this->request('POST', 'ticket_articles', $data);
} }