Files
Frank Schwenk 01de7ed4fb feat: SMTP mail stack and separate server.env deploy
Add mail.php with STARTTLS sending, test scripts, server.env split from
local .env, admin@ postbox docs, DKIM DNS support-ticket notes, and todo 11
for boka relay.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 23:19:03 +02:00

78 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
/**
* Load configuration from private/server.env (outside document root).
* Local .env is never deployed — see server.env.example.
*/
function bootstrap(): array
{
static $config = null;
if ($config !== null) {
return $config;
}
$config = loadEnvFile(envFilePath());
return $config;
}
function envFilePath(): string
{
$baseDir = dirname(__DIR__);
// Webspace: private/config/bootstrap.php → private/server.env
if (basename($baseDir) === 'private') {
return $baseDir . '/server.env';
}
// Local repo: .env on this machine (never deployed)
$local = $baseDir . '/.env';
if (is_readable($local)) {
return $local;
}
return $baseDir . '/server.env';
}
function env(string $key, ?string $default = null): ?string
{
$value = bootstrap()[$key] ?? null;
return ($value === null || $value === '') ? $default : $value;
}
function loadEnvFile(string $path): array
{
if (!is_readable($path)) {
return [];
}
$vars = [];
foreach (file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
$line = trim($line);
if ($line === '' || str_starts_with($line, '#')) {
continue;
}
if (!str_contains($line, '=')) {
continue;
}
[$key, $value] = explode('=', $line, 2);
$vars[trim($key)] = trim($value);
}
return $vars;
}
function privateDataDir(): string
{
return dirname(__DIR__) . '/data';
}