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.
44 lines
1.5 KiB
PHP
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;
|
|
}
|
|
} |