Files
plugi/extensions/plugi-ext-form/admin/Classes/Finishers/SendConfirmationEmailToSubmitter.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

44 lines
1.5 KiB
PHP

<?php
namespace Plugi\Extensions\Form\Finishers;
class SendConfirmationEmailToSubmitter extends DefaultFinisher
{
public function execute(): bool
{
$recipientField = $this->options['recipientField'] ?? null;
if (!is_string($recipientField) || $recipientField === '') {
return false;
}
$emailFieldExists = false;
foreach ($this->getFormFields() as $field) {
if (($field['name'] ?? null) === $recipientField && ($field['type'] ?? null) === 'email') {
$emailFieldExists = true;
break;
}
}
if (!$emailFieldExists) {
return false;
}
$recipient = $this->getEntryFields()[$recipientField] ?? null;
if (!is_string($recipient) || filter_var($recipient, FILTER_VALIDATE_EMAIL) === false) {
return false;
}
$subject = $this->options['subject'] ?? null;
$message = $this->options['message'] ?? null;
if (!is_string($subject) || trim($subject) === '' || strpbrk($subject, "\r\n") !== false || !is_string($message) || trim($message) === '') {
return false;
}
return $this->sendMail($recipient, $subject, $message);
}
protected function sendMail(string $recipient, string $subject, string $message): bool
{
$mailer = phpb_instance('mail');
return $mailer !== null && $mailer->send($recipient, $subject, $message) === true;
}
}