52 lines
1.9 KiB
PHP
52 lines
1.9 KiB
PHP
<?php
|
||
|
||
if (!function_exists('get_env_var')) {
|
||
function get_env_var($key, $default = null) {
|
||
if (isset($_ENV[$key])) return $_ENV[$key];
|
||
$val = getenv($key);
|
||
return $val === false ? $default : $val;
|
||
}
|
||
}
|
||
|
||
if (!function_exists('load_dot_env')) {
|
||
function load_dot_env($path) {
|
||
if (!file_exists($path) || !is_readable($path)) return;
|
||
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||
foreach ($lines as $line) {
|
||
if (strpos(trim($line), '#') === 0) continue;
|
||
list($key, $val) = explode('=', $line, 2) + [null, null];
|
||
if ($key === null) continue;
|
||
$key = trim($key);
|
||
$val = trim($val);
|
||
if (preg_match('/^"(.*)"$/', $val, $matches)) $val = $matches[1];
|
||
elseif (preg_match("/'(.*)'/ ", $val, $matches)) $val = $matches[1];
|
||
if (!array_key_exists($key, $_SERVER) && !array_key_exists($key, $_ENV)) {
|
||
putenv("$key=$val");
|
||
$_ENV[$key] = $val;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
$dotenv_path = __DIR__ . '/../.env';
|
||
if (file_exists($dotenv_path)) {
|
||
load_dot_env($dotenv_path);
|
||
}
|
||
|
||
return [
|
||
'transport' => get_env_var('MAIL_TRANSPORT', 'smtp'),
|
||
'smtp_host' => get_env_var('SMTP_HOST'),
|
||
'smtp_port' => get_env_var('SMTP_PORT', 587),
|
||
'smtp_secure' => get_env_var('SMTP_SECURE', 'tls'), // tls or ssl
|
||
'smtp_user' => get_env_var('SMTP_USER'),
|
||
'smtp_pass' => get_env_var('SMTP_PASS'),
|
||
'from_email' => get_env_var('MAIL_FROM'),
|
||
'from_name' => get_env_var('MAIL_FROM_NAME'),
|
||
'reply_to' => get_env_var('MAIL_REPLY_TO'),
|
||
|
||
// Optional DKIM signing
|
||
'dkim_domain' => get_env_var('DKIM_DOMAIN', ''),
|
||
'dkim_selector' => get_env_var('DKIM_SELECTOR', 'default'),
|
||
'dkim_private_key_path' => get_env_var('DKIM_PRIVATE_KEY_PATH', ''), // Path to the private key file
|
||
];
|