index-soutien/api/brevo-config.php

32 lines
1,006 B
PHP
Raw Normal View History

2026-03-04 13:39:20 +01:00
<?php
// Load environment variables from .env file
$env_file = __DIR__ . '/.env';
if (file_exists($env_file)) {
$lines = file($env_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) continue;
if (strpos($line, '=') !== false) {
list($key, $value) = explode('=', $line, 2);
$key = trim($key);
$value = trim($value, '"\'');
putenv("$key=$value");
$_ENV[$key] = $value;
$_SERVER[$key] = $value;
}
}
}
define('BREVO_API_KEY', getenv('BREVO_API_KEY') ?: '');
define('BREVO_LIST_ID', (int)(getenv('BREVO_LIST_ID') ?: 2)); // Must be int, not string
define('BREVO_API_URL', 'https://api.brevo.com/v3/contacts');
if (empty(BREVO_API_KEY)) {
error_log('[BREVO] API key not configured');
}
$allowed_origins = getenv('ALLOWED_ORIGINS') ? explode(',', getenv('ALLOWED_ORIGINS')) : ['*'];
define('ALLOWED_ORIGINS', $allowed_origins);