getUri()->getPath(), '/') !== self::PATH) { return $handler->handle($request); } if (strtoupper($request->getMethod()) !== 'POST') { return new JsonResponse(['success' => false, 'error' => 'POST only'], 405); } try { $settings = GeneralUtility::makeInstance(ExtensionSettings::class); if (!$settings->enabled()) { return new JsonResponse(['success' => false, 'error' => 'Feedback is disabled'], 403); } if ($settings->mailTo() === []) { return new JsonResponse(['success' => false, 'error' => 'No recipient configured (extension configuration fe_comment)'], 503); } $payload = json_decode((string)$request->getBody(), true); $entries = is_array($payload['entries'] ?? null) ? $payload['entries'] : []; $clean = []; foreach (array_slice($entries, 0, self::MAX_ENTRIES) as $entry) { $url = mb_substr(trim((string)($entry['url'] ?? '')), 0, self::MAX_URL_LENGTH); $comment = mb_substr(trim((string)($entry['comment'] ?? '')), 0, self::MAX_COMMENT_LENGTH); if ($comment !== '') { $clean[] = ['url' => $url, 'comment' => $comment]; } } if ($clean === []) { return new JsonResponse(['success' => false, 'error' => 'No entries'], 400); } $host = $request->getUri()->getHost(); $lines = ['Page feedback from ' . $host, 'Submitted: ' . date('Y-m-d H:i'), str_repeat('-', 60), '']; foreach ($clean as $i => $entry) { $lines[] = ($i + 1) . ') ' . ($entry['url'] !== '' ? $entry['url'] : '(no url)'); $lines[] = $entry['comment']; $lines[] = ''; } $mail = GeneralUtility::makeInstance(MailMessage::class); $mail->to(...$settings->mailTo()) ->subject($settings->subject() . ' — ' . $host . ' (' . count($clean) . ')') ->text(implode("\n", $lines)); if ($settings->mailCc() !== []) { $mail->cc(...$settings->mailCc()); } if ($settings->mailBcc() !== []) { $mail->bcc(...$settings->mailBcc()); } // v14: MailMessage no longer has send() - the Mailer service does. GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\Mailer::class)->send($mail); return new JsonResponse(['success' => true, 'sent' => count($clean)]); } catch (\Throwable $e) { return new JsonResponse(['success' => false, 'error' => 'Send failed: ' . $e->getMessage()], 500); } } }