Files
plugi/extensions/plugi-ext-form/admin/Classes/Finishers/SendEmailToAdmin.php
T
deepDiverPaul dfe1e40e58 add configurable SMTP mail delivery
Add a core SMTP mailer with configurable transport, authentication, and sender settings. Route form confirmation and admin notifications through the core mailer, and add tests for SMTP delivery, failure cases, and finisher integration.
2026-11-24 11:48:31 +01:00

37 lines
1.1 KiB
PHP

<?php
namespace Plugi\Extensions\Form\Finishers;
use Plugi\Extensions;
class SendEmailToAdmin extends DefaultFinisher
{
public function execute(): bool
{
$settings = Extensions::getSettings('form');
$to = $settings['email']['value'] ?? null;
if (!is_string($to) || filter_var($to, FILTER_VALIDATE_EMAIL) === false) {
return false;
}
$subject = 'Form submission: '.$this->getFormName();
$message = $this->getNiceFields();
$mailer = phpb_instance('mail');
return $mailer !== null && $mailer->send($to, $subject, $message) === true;
}
private function getNiceFields(): string {
$text = '';
foreach ($this->getFormFields() as $field) {
$name = $field['name'] ?? '';
$label = $field['label'] ?? $name;
$value = $this->getEntryFields()[$name] ?? '';
if (is_array($value)) {
$value = implode(', ', array_map('strval', $value));
} elseif (!is_scalar($value)) {
$value = '';
}
$text .= $label . ': ' . $value . "\n";
}
return $text;
}
}