mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
smtp: add notify_email field; fix admin notification sent to no-reply sender
This commit is contained in:
@@ -39,22 +39,34 @@ class SmtpRelay {
|
||||
*/
|
||||
public static function getSettings(Database $db): array {
|
||||
$stmt = $db->getPDO()->query(
|
||||
"SELECT host, port, encryption, username, password, from_email, from_name
|
||||
"SELECT host, port, encryption, username, password, from_email, from_name, notify_email
|
||||
FROM v_smtp_active LIMIT 1"
|
||||
);
|
||||
$row = $stmt->fetch();
|
||||
|
||||
return $row ?: [
|
||||
'host' => '',
|
||||
'port' => 587,
|
||||
'encryption' => 'tls',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'from_email' => '',
|
||||
'from_name' => 'XAMXAM',
|
||||
'host' => '',
|
||||
'port' => 587,
|
||||
'encryption' => 'tls',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'from_email' => '',
|
||||
'from_name' => 'XAMXAM',
|
||||
'notify_email' => '',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the address that should receive admin notification emails.
|
||||
* Uses notify_email when set, falls back to from_email.
|
||||
*/
|
||||
public static function getNotifyEmail(Database $db): string
|
||||
{
|
||||
$s = self::getSettings($db);
|
||||
$notify = trim($s['notify_email'] ?? '');
|
||||
return $notify !== '' ? $notify : trim($s['from_email'] ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Upsert SMTP settings.
|
||||
*
|
||||
@@ -71,25 +83,27 @@ class SmtpRelay {
|
||||
|
||||
$stmt = $db->getPDO()->prepare(
|
||||
"UPDATE smtp_settings
|
||||
SET host = :host,
|
||||
port = :port,
|
||||
encryption = :encryption,
|
||||
username = :username,
|
||||
password = :password,
|
||||
from_email = :from_email,
|
||||
from_name = :from_name,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
SET host = :host,
|
||||
port = :port,
|
||||
encryption = :encryption,
|
||||
username = :username,
|
||||
password = :password,
|
||||
from_email = :from_email,
|
||||
from_name = :from_name,
|
||||
notify_email = :notify_email,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = 1"
|
||||
);
|
||||
|
||||
$stmt->execute([
|
||||
':host' => trim($merged['host']),
|
||||
':port' => $port,
|
||||
':encryption' => $encryption,
|
||||
':username' => trim($merged['username']),
|
||||
':password' => $merged['password'],
|
||||
':from_email' => trim($merged['from_email']),
|
||||
':from_name' => trim($merged['from_name']),
|
||||
':host' => trim($merged['host']),
|
||||
':port' => $port,
|
||||
':encryption' => $encryption,
|
||||
':username' => trim($merged['username']),
|
||||
':password' => $merged['password'],
|
||||
':from_email' => trim($merged['from_email']),
|
||||
':from_name' => trim($merged['from_name']),
|
||||
':notify_email' => trim($merged['notify_email'] ?? ''),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user