36782-vm/mail/config.php
2025-12-28 14:19:17 +00:00

52 lines
1.9 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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
];