Upload via GUI (346 Dateien)
This commit is contained in:
@@ -15,7 +15,27 @@ function smtp_last_error(): string
|
||||
return func_num_args() > 0 ? ($lastError = func_get_arg(0)) : $lastError;
|
||||
}
|
||||
|
||||
function send_mail(string $to, string $subject, string $htmlBody, ?string $fromOverride = null): bool
|
||||
/**
|
||||
* Sendet eine Mail. Scheitert der Versand, obwohl ein Versandweg eingerichtet ist, kommt die Mail in die Warteschlange
|
||||
* (includes/mail_queue.php) und wird später erneut versucht; der Rückgabewert bleibt dann false, mail_last_queued() ist true.
|
||||
* $queue = false für Test-Mails und für die Wiederholungsläufe der Warteschlange selbst.
|
||||
*/
|
||||
function send_mail(string $to, string $subject, string $htmlBody, ?string $fromOverride = null, bool $queue = true): bool
|
||||
{
|
||||
mail_attempted(false);
|
||||
mail_last_queued(false);
|
||||
$ok = send_mail_now($to, $subject, $htmlBody, $fromOverride);
|
||||
if (!$ok && $queue && mail_attempted() && mail_queue_enabled()) {
|
||||
try {
|
||||
if (mail_queue_add(get_db(), $to, $subject, $htmlBody, $fromOverride, smtp_last_error()) !== null) mail_last_queued(true);
|
||||
} catch (Throwable $e) {
|
||||
error_log('send_mail queue: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
function send_mail_now(string $to, string $subject, string $htmlBody, ?string $fromOverride = null): bool
|
||||
{
|
||||
$cfg = [
|
||||
'enabled' => get_setting('mail_enabled', config()['mail']['enabled'] ? '1' : '0') === '1',
|
||||
@@ -45,6 +65,7 @@ function send_mail(string $to, string $subject, string $htmlBody, ?string $fromO
|
||||
(string) $own['smtp_username'],
|
||||
$own['smtp_password_enc'] ? decrypt_secret($own['smtp_password_enc']) : '',
|
||||
);
|
||||
mail_attempted(true);
|
||||
$ok = $mailer->send($to, $fromHeader, $subject, $htmlBody);
|
||||
if (!$ok) {
|
||||
smtp_last_error($mailer->getLastError());
|
||||
@@ -62,6 +83,7 @@ function send_mail(string $to, string $subject, string $htmlBody, ?string $fromO
|
||||
get_setting('smtp_username', ''),
|
||||
decrypt_secret(get_setting('smtp_password', '')),
|
||||
);
|
||||
mail_attempted(true);
|
||||
$ok = $mailer->send($to, $fromHeader, $subject, $htmlBody);
|
||||
if (!$ok) {
|
||||
smtp_last_error($mailer->getLastError());
|
||||
@@ -75,6 +97,7 @@ function send_mail(string $to, string $subject, string $htmlBody, ?string $fromO
|
||||
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
|
||||
$headers .= "From: {$fromHeader}\r\n";
|
||||
|
||||
mail_attempted(true);
|
||||
return @mail($to, $subject, $htmlBody, $headers);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user