add test batches

This commit is contained in:
root
2026-06-08 23:45:55 -04:00
parent c792b8be05
commit 8d4d610b82
1480 changed files with 22587 additions and 10762 deletions
+9 -11
View File
@@ -7,7 +7,9 @@ use PHPMailer\PHPMailer\PHPMailer;
class EmailDispatchService
{
public function __construct(private EmailProfileService $profiles) {}
public function __construct(private EmailProfileService $profiles)
{
}
public function send(
string $recipient,
@@ -23,7 +25,6 @@ class EmailDispatchService
if (empty($cfg['host']) || empty($cfg['user']) || $cfg['pass'] === '') {
logger()->error("[mail:$profile] Missing SMTP config (host/user/pass). Check MAIL_{$this->profiles->envKeyFromProfile($profile)}_* or MAIL_DEFAULT_*/MAIL_*.");
return false;
}
@@ -60,7 +61,7 @@ class EmailDispatchService
'ssl' => [
'verify_peer' => $verifyPeer,
'verify_peer_name' => $verifyPeer,
'allow_self_signed' => ! $verifyPeer,
'allow_self_signed' => !$verifyPeer,
],
];
@@ -68,17 +69,17 @@ class EmailDispatchService
$mail->Debugoutput = 'error_log';
$mail->setFrom($cfg['fromEmail'], $cfg['fromName']);
if (! empty($cfg['returnPath'])) {
if (!empty($cfg['returnPath'])) {
$mail->Sender = $cfg['returnPath'];
}
$mail->clearReplyTos();
$rtEmail = env('MAIL_DEFAULT_REPLY_TO');
$rtName = env('MAIL_DEFAULT_REPLY_TO_NAME');
if (! $rtEmail || ! filter_var($rtEmail, FILTER_VALIDATE_EMAIL)) {
if (!$rtEmail || !filter_var($rtEmail, FILTER_VALIDATE_EMAIL)) {
$rtEmail = $replyToEmail ?: ($cfg['replyTo'] ?: $cfg['fromEmail']);
}
if (! $rtName) {
if (!$rtName) {
$rtName = $replyToName ?: ($cfg['replyToName'] ?: $cfg['fromName']);
}
$rtName = $this->profiles->sanitizeReplyToName($rtName, $cfg['fromName']);
@@ -86,7 +87,7 @@ class EmailDispatchService
$mail->addReplyTo($rtEmail, $rtName);
}
if (! empty($cfg['dkim']['domain']) && ! empty($cfg['dkim']['private']) && ! empty($cfg['dkim']['selector'])) {
if (!empty($cfg['dkim']['domain']) && !empty($cfg['dkim']['private']) && !empty($cfg['dkim']['selector'])) {
$mail->DKIM_domain = $cfg['dkim']['domain'];
$mail->DKIM_private = $cfg['dkim']['private'];
$mail->DKIM_selector = $cfg['dkim']['selector'];
@@ -96,7 +97,7 @@ class EmailDispatchService
$mail->addAddress($recipient);
foreach ($attachments as $att) {
if (! empty($att['path']) && is_file($att['path'])) {
if (!empty($att['path']) && is_file($att['path'])) {
$mail->addAttachment($att['path'], $att['name'] ?? '');
}
}
@@ -110,17 +111,14 @@ class EmailDispatchService
if ($ok) {
logger()->info("[mail:$profile] Sent to {$recipient}, subj='{$subject}' via {$cfg['host']}:{$cfg['port']}/{$cfg['encryption']}");
return true;
}
logger()->error("[mail:$profile] Failed: {$mail->ErrorInfo}. Debug: {$dbg}");
return false;
} catch (MailerException $e) {
$dbg = $debugEnabled ? (ob_get_clean() ?: '') : '';
logger()->error("[mail:$profile] Exception: {$e->getMessage()} | PHPMailer: {$mail->ErrorInfo} | Debug: {$dbg}");
return false;
}
}