13131
This commit is contained in:
parent
fe7ebfad4d
commit
cdb6be6798
@ -90,6 +90,11 @@ class MailService
|
|||||||
}
|
}
|
||||||
private static function loadConfig(): array
|
private static function loadConfig(): array
|
||||||
{
|
{
|
||||||
|
static $cachedConfig = null;
|
||||||
|
if (is_array($cachedConfig)) {
|
||||||
|
return $cachedConfig;
|
||||||
|
}
|
||||||
|
|
||||||
$configPath = __DIR__ . '/config.php';
|
$configPath = __DIR__ . '/config.php';
|
||||||
if (!file_exists($configPath)) {
|
if (!file_exists($configPath)) {
|
||||||
throw new \RuntimeException('Mail config not found. Copy mail/config.sample.php to mail/config.php and fill in credentials.');
|
throw new \RuntimeException('Mail config not found. Copy mail/config.sample.php to mail/config.php and fill in credentials.');
|
||||||
@ -98,7 +103,9 @@ class MailService
|
|||||||
if (!is_array($cfg)) {
|
if (!is_array($cfg)) {
|
||||||
throw new \RuntimeException('Invalid mail config format: expected array');
|
throw new \RuntimeException('Invalid mail config format: expected array');
|
||||||
}
|
}
|
||||||
return $cfg;
|
|
||||||
|
$cachedConfig = $cfg;
|
||||||
|
return $cachedConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a contact message
|
// Send a contact message
|
||||||
|
|||||||
@ -2,14 +2,17 @@
|
|||||||
// Mail configuration sourced from environment variables.
|
// Mail configuration sourced from environment variables.
|
||||||
// No secrets are stored here; the file just maps env -> config array for MailService.
|
// No secrets are stored here; the file just maps env -> config array for MailService.
|
||||||
|
|
||||||
|
if (!function_exists('env_val')) {
|
||||||
function env_val(string $key, $default = null) {
|
function env_val(string $key, $default = null) {
|
||||||
$v = getenv($key);
|
$v = getenv($key);
|
||||||
return ($v === false || $v === null || $v === '') ? $default : $v;
|
return ($v === false || $v === null || $v === '') ? $default : $v;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Fallback: if critical vars are missing from process env, try to parse executor/.env
|
// Fallback: if critical vars are missing from process env, try to parse executor/.env
|
||||||
// This helps in web/Apache contexts where .env is not exported.
|
// This helps in web/Apache contexts where .env is not exported.
|
||||||
// Supports simple KEY=VALUE lines; ignores quotes and comments.
|
// Supports simple KEY=VALUE lines; ignores quotes and comments.
|
||||||
|
if (!function_exists('load_dotenv_if_needed')) {
|
||||||
function load_dotenv_if_needed(array $keys): void {
|
function load_dotenv_if_needed(array $keys): void {
|
||||||
$missing = array_filter($keys, fn($k) => getenv($k) === false || getenv($k) === '');
|
$missing = array_filter($keys, fn($k) => getenv($k) === false || getenv($k) === '');
|
||||||
if (empty($missing)) return;
|
if (empty($missing)) return;
|
||||||
@ -32,6 +35,7 @@ function load_dotenv_if_needed(array $keys): void {
|
|||||||
$loaded = true;
|
$loaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
load_dotenv_if_needed([
|
load_dotenv_if_needed([
|
||||||
'MAIL_TRANSPORT','SMTP_HOST','SMTP_PORT','SMTP_SECURE','SMTP_USER','SMTP_PASS',
|
'MAIL_TRANSPORT','SMTP_HOST','SMTP_PORT','SMTP_SECURE','SMTP_USER','SMTP_PASS',
|
||||||
|
|||||||
6552
mail/mail.log
6552
mail/mail.log
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user