add test batches
This commit is contained in:
@@ -11,17 +11,17 @@ class EmailAttachmentService
|
||||
if ($files instanceof UploadedFile) {
|
||||
$files = [$files];
|
||||
}
|
||||
if (! is_array($files)) {
|
||||
if (!is_array($files)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$out = [];
|
||||
foreach ($files as $file) {
|
||||
if (! $file instanceof UploadedFile || ! $file->isValid()) {
|
||||
if (!$file instanceof UploadedFile || !$file->isValid()) {
|
||||
continue;
|
||||
}
|
||||
$path = $file->getRealPath();
|
||||
if (! $path || ! is_file($path)) {
|
||||
if (!$path || !is_file($path)) {
|
||||
continue;
|
||||
}
|
||||
$out[] = [
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class EmailExtractorService
|
||||
|
||||
$needToAdd = [];
|
||||
foreach ($dbSet as $email => $_) {
|
||||
if (! isset($csvSet[$email])) {
|
||||
if (!isset($csvSet[$email])) {
|
||||
$needToAdd[] = $email;
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,6 @@ class EmailExtractorService
|
||||
$out[] = $email;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($out));
|
||||
}
|
||||
|
||||
@@ -93,7 +92,6 @@ class EmailExtractorService
|
||||
$pattern = '/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/i';
|
||||
preg_match_all($pattern, $text, $matches);
|
||||
$emails = $matches[0] ?? [];
|
||||
|
||||
return $this->normalizeEmailArray($emails);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ class EmailProfileService
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
};
|
||||
|
||||
@@ -91,7 +90,6 @@ class EmailProfileService
|
||||
if ($trimmed === '' || preg_match('/^no[- ]?repl(?:y|ay)$/i', $trimmed)) {
|
||||
return $fallback;
|
||||
}
|
||||
|
||||
return $trimmed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class EmailSenderOptionsService
|
||||
$json = env('MAIL_SENDERS', '{}');
|
||||
$arr = json_decode($json, true);
|
||||
|
||||
if (! is_array($arr) || empty($arr)) {
|
||||
if (!is_array($arr) || empty($arr)) {
|
||||
$smtpUser = getenv('SMTP_USER') ?: '';
|
||||
$name = 'Al Rahma Sunday School';
|
||||
|
||||
@@ -17,7 +17,7 @@ class EmailSenderOptionsService
|
||||
'key' => 'general',
|
||||
'name' => $name,
|
||||
'email' => $smtpUser,
|
||||
'label' => trim($name.($smtpUser ? " <{$smtpUser}>" : '')),
|
||||
'label' => trim($name . ($smtpUser ? " <{$smtpUser}>" : '')),
|
||||
]];
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class EmailSenderOptionsService
|
||||
'key' => (string) $key,
|
||||
'name' => (string) $name,
|
||||
'email' => (string) $email,
|
||||
'label' => trim($name.($email ? " <{$email}>" : '')),
|
||||
'label' => trim($name . ($email ? " <{$email}>" : '')),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user