Initial version
This commit is contained in:
commit
011154eee1
15
.env
Normal file
15
.env
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
# Mailer Configuration
|
||||||
|
# Choose transport: 'smtp' or 'native' (for sendmail)
|
||||||
|
MAIL_TRANSPORT=smtp
|
||||||
|
|
||||||
|
# SMTP Server Settings
|
||||||
|
SMTP_HOST=smtp.example.com
|
||||||
|
SMTP_PORT=587
|
||||||
|
SMTP_SECURE=tls
|
||||||
|
SMTP_USER=your_username
|
||||||
|
SMTP_PASS=your_password
|
||||||
|
|
||||||
|
# Email 'From' and 'Reply-To' Addresses
|
||||||
|
MAIL_FROM=you@example.com
|
||||||
|
MAIL_FROM_NAME="Ava Reed Portfolio"
|
||||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
node_modules/
|
||||||
|
*/node_modules/
|
||||||
|
*/build/
|
||||||
18
.htaccess
Normal file
18
.htaccess
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
DirectoryIndex index.php index.html
|
||||||
|
Options -Indexes
|
||||||
|
Options -MultiViews
|
||||||
|
|
||||||
|
RewriteEngine On
|
||||||
|
|
||||||
|
# 0) Serve existing files/directories as-is
|
||||||
|
RewriteCond %{REQUEST_FILENAME} -f [OR]
|
||||||
|
RewriteCond %{REQUEST_FILENAME} -d
|
||||||
|
RewriteRule ^ - [L]
|
||||||
|
|
||||||
|
# 1) Internal map: /page or /page/ -> /page.php (if such PHP file exists)
|
||||||
|
RewriteCond %{REQUEST_FILENAME}.php -f
|
||||||
|
RewriteRule ^(.+?)/?$ $1.php [L]
|
||||||
|
|
||||||
|
# 2) Optional: strip trailing slash for non-directories (keeps .php links working)
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteRule ^(.+)/$ $1 [R=301,L]
|
||||||
0
.perm_test_apache
Normal file
0
.perm_test_apache
Normal file
0
.perm_test_exec
Normal file
0
.perm_test_exec
Normal file
17
db/config.php
Normal file
17
db/config.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
// Generated by setup_mariadb_project.sh — edit as needed.
|
||||||
|
define('DB_HOST', '127.0.0.1');
|
||||||
|
define('DB_NAME', 'app_30839');
|
||||||
|
define('DB_USER', 'app_30839');
|
||||||
|
define('DB_PASS', '8778efb8-3001-4129-9a4a-2b99f7813893');
|
||||||
|
|
||||||
|
function db() {
|
||||||
|
static $pdo;
|
||||||
|
if (!$pdo) {
|
||||||
|
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||||
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return $pdo;
|
||||||
|
}
|
||||||
165
index.php
Normal file
165
index.php
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
$message = null;
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] === 'POST') {
|
||||||
|
require_once __DIR__ . '/mail/MailService.php';
|
||||||
|
$res = MailService::sendContactMessage(
|
||||||
|
$_POST['name'] ?? '',
|
||||||
|
$_POST['email'] ?? '',
|
||||||
|
$_POST['message'] ?? ''
|
||||||
|
);
|
||||||
|
if (!empty($res['success'])) {
|
||||||
|
$_SESSION['contact_form_status'] = 'success';
|
||||||
|
} else {
|
||||||
|
$_SESSION['contact_form_status'] = 'error';
|
||||||
|
$_SESSION['contact_form_error'] = $res['error'] ?? 'An unknown error occurred.';
|
||||||
|
}
|
||||||
|
header('Location: ' . $_SERVER['PHP_SELF'] . '#contact');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_SESSION['contact_form_status'])) {
|
||||||
|
if ($_SESSION['contact_form_status'] === 'success') {
|
||||||
|
$message = '<div class="alert alert-success">Your message has been sent successfully!</div>';
|
||||||
|
} else {
|
||||||
|
$error_message = $_SESSION['contact_form_error'] ?? 'An unknown error occurred.';
|
||||||
|
$message = '<div class="alert alert-danger">Failed to send message. Please try again later. Error: ' . htmlspecialchars($error_message) . '</div>';
|
||||||
|
}
|
||||||
|
unset($_SESSION['contact_form_status']);
|
||||||
|
unset($_SESSION['contact_form_error']);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Ava Reed | Designer & Developer</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-dark fixed-top">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" href="#">Ava Reed</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav ms-auto">
|
||||||
|
<li class="nav-item"><a class="nav-link" href="#work">Work</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="#services">Services</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="#about">About</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="#contact">Contact</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<header class="hero text-center">
|
||||||
|
<div class="container">
|
||||||
|
<h1 class="display-4">Ava Reed: Creative Designer & Developer</h1>
|
||||||
|
<p class="lead">Crafting beautiful and functional digital experiences.</p>
|
||||||
|
<a href="#contact" class="btn btn-light btn-lg">Contact Me</a>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section id="work" class="section">
|
||||||
|
<div class="container">
|
||||||
|
<h2 class="text-center mb-5">My Work</h2>
|
||||||
|
<div class="row g-4">
|
||||||
|
<?php for ($i = 1; $i <= 6; $i++): ?>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card">
|
||||||
|
<img src="https://picsum.photos/seed/work<?php echo $i; ?>/600/400" class="card-img-top" alt="Portfolio project example <?php echo $i; ?>">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Project <?php echo $i; ?></h5>
|
||||||
|
<p class="card-text">A brief description of the project.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endfor; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="services" class="section bg-light">
|
||||||
|
<div class="container">
|
||||||
|
<h2 class="text-center mb-5">Services</h2>
|
||||||
|
<div class="row text-center">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="mb-3"><i class="bi bi-palette fs-1 text-primary"></i></div>
|
||||||
|
<h4>Web Design</h4>
|
||||||
|
<p>Creating stunning and intuitive user interfaces.</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="mb-3"><i class="bi bi-code-slash fs-1 text-primary"></i></div>
|
||||||
|
<h4>Development</h4>
|
||||||
|
<p>Building responsive and high-performance websites.</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="mb-3"><i class="bi bi-vector-pen fs-1 text-primary"></i></div>
|
||||||
|
<h4>Branding</h4>
|
||||||
|
<p>Developing unique and memorable brand identities.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="about" class="section">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col-md-4 text-center">
|
||||||
|
<img src="https://picsum.photos/seed/avatar/256/256" class="img-fluid rounded-circle" alt="Ava Reed">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<h2 class="mb-4">About Me</h2>
|
||||||
|
<p>I am a passionate and detail-oriented designer and developer with a love for creating beautiful and intuitive digital products. With a background in both art and computer science, I bring a unique perspective to every project.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="contact" class="section bg-light">
|
||||||
|
<div class="container">
|
||||||
|
<h2 class="text-center mb-5">Get in Touch</h2>
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<?php if ($message) echo $message; ?>
|
||||||
|
<form id="contactForm" method="POST" action="#contact" class="needs-validation" novalidate>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="name" class="form-label">Name</label>
|
||||||
|
<input type="text" class="form-control" id="name" name="name" required>
|
||||||
|
<div class="invalid-feedback">Please enter your name.</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="email" class="form-label">Email</label>
|
||||||
|
<input type="email" class="form-control" id="email" name="email" required>
|
||||||
|
<div class="invalid-feedback">Please enter a valid email address.</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="message" class="form-label">Message</label>
|
||||||
|
<textarea class="form-control" id="message" name="message" rows="5" required></textarea>
|
||||||
|
<div class="invalid-feedback">Please enter a message.</div>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Send Message</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<footer class="text-center py-4">
|
||||||
|
<div class="container">
|
||||||
|
<a href="#" class="text-dark mx-2"><i class="bi bi-github"></i></a>
|
||||||
|
<a href="#" class="text-dark mx-2"><i class="bi bi-linkedin"></i></a>
|
||||||
|
<p class="mt-3">© <?php echo date("Y"); ?> Ava Reed. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script src="assets/js/main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
169
mail/MailService.php
Normal file
169
mail/MailService.php
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
<?php
|
||||||
|
// Minimal mail service for the workspace app (VM).
|
||||||
|
// Usage:
|
||||||
|
// require_once __DIR__ . '/MailService.php';
|
||||||
|
// MailService::sendContactMessage($name, $email, $message, $attachments, $subject);
|
||||||
|
|
||||||
|
class MailService
|
||||||
|
{
|
||||||
|
private static function loadConfig(): array
|
||||||
|
{
|
||||||
|
$configPath = __DIR__ . '/config.php';
|
||||||
|
if (!file_exists($configPath)) {
|
||||||
|
throw new \RuntimeException('Mail config not found. Copy mail/config.sample.php to mail/config.php and fill in credentials.');
|
||||||
|
}
|
||||||
|
$cfg = require $configPath;
|
||||||
|
if (!is_array($cfg)) {
|
||||||
|
throw new \RuntimeException('Invalid mail config format: expected array');
|
||||||
|
}
|
||||||
|
return $cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send a contact message
|
||||||
|
// $to can be: a single email string, a comma-separated list, an array of emails, or null (fallback to MAIL_TO/MAIL_FROM)
|
||||||
|
public static function sendContactMessage(string $name, string $email, string $message, $to = null, string $subject = 'New contact form')
|
||||||
|
{
|
||||||
|
$cfg = self::loadConfig();
|
||||||
|
|
||||||
|
// Try Composer autoload if available (for PHPMailer)
|
||||||
|
$autoload = __DIR__ . '/../vendor/autoload.php';
|
||||||
|
if (file_exists($autoload)) {
|
||||||
|
require_once $autoload;
|
||||||
|
}
|
||||||
|
// Fallback to system-wide PHPMailer (installed via apt: libphp-phpmailer)
|
||||||
|
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||||
|
// Debian/Ubuntu package layout (libphp-phpmailer)
|
||||||
|
@require_once 'libphp-phpmailer/autoload.php';
|
||||||
|
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||||
|
@require_once 'libphp-phpmailer/src/Exception.php';
|
||||||
|
@require_once 'libphp-phpmailer/src/SMTP.php';
|
||||||
|
@require_once 'libphp-phpmailer/src/PHPMailer.php';
|
||||||
|
}
|
||||||
|
// Alternative layout (older PHPMailer package names)
|
||||||
|
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||||
|
@require_once 'PHPMailer/src/Exception.php';
|
||||||
|
@require_once 'PHPMailer/src/SMTP.php';
|
||||||
|
@require_once 'PHPMailer/src/PHPMailer.php';
|
||||||
|
}
|
||||||
|
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||||
|
@require_once 'PHPMailer/Exception.php';
|
||||||
|
@require_once 'PHPMailer/SMTP.php';
|
||||||
|
@require_once 'PHPMailer/PHPMailer.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$transport = $cfg['transport'] ?? 'smtp';
|
||||||
|
if ($transport === 'smtp' && class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||||
|
return self::sendViaPHPMailer($cfg, $name, $email, $message, $to, $subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: attempt native mail() — works only if MTA is configured on the VM
|
||||||
|
return self::sendViaNativeMail($cfg, $name, $email, $message, $to, $subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function sendViaPHPMailer(array $cfg, string $name, string $email, string $body, $to, string $subject)
|
||||||
|
{
|
||||||
|
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
|
||||||
|
try {
|
||||||
|
$mail->isSMTP();
|
||||||
|
$mail->Host = $cfg['smtp_host'] ?? '';
|
||||||
|
$mail->Port = (int)($cfg['smtp_port'] ?? 587);
|
||||||
|
$secure = $cfg['smtp_secure'] ?? 'tls';
|
||||||
|
if ($secure === 'ssl') $mail->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_SMTPS;
|
||||||
|
elseif ($secure === 'tls') $mail->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;
|
||||||
|
else $mail->SMTPSecure = false;
|
||||||
|
$mail->SMTPAuth = true;
|
||||||
|
$mail->Username = $cfg['smtp_user'] ?? '';
|
||||||
|
$mail->Password = $cfg['smtp_pass'] ?? '';
|
||||||
|
|
||||||
|
$fromEmail = $cfg['from_email'] ?? 'no-reply@localhost';
|
||||||
|
$fromName = $cfg['from_name'] ?? 'App';
|
||||||
|
$mail->setFrom($fromEmail, $fromName);
|
||||||
|
|
||||||
|
// Use Reply-To for the user's email to avoid spoofing From
|
||||||
|
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$mail->addReplyTo($email, $name ?: $email);
|
||||||
|
}
|
||||||
|
if (!empty($cfg['reply_to'])) {
|
||||||
|
$mail->addReplyTo($cfg['reply_to']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destination: prefer dynamic recipients ($to), fallback to MAIL_TO, then MAIL_FROM
|
||||||
|
$toList = [];
|
||||||
|
if ($to) {
|
||||||
|
if (is_string($to)) {
|
||||||
|
// allow comma-separated list
|
||||||
|
$toList = array_map('trim', explode(',', $to));
|
||||||
|
} elseif (is_array($to)) {
|
||||||
|
$toList = $to;
|
||||||
|
}
|
||||||
|
} elseif (!empty(getenv('MAIL_TO'))) {
|
||||||
|
$toList = array_map('trim', explode(',', getenv('MAIL_TO')));
|
||||||
|
}
|
||||||
|
$added = 0;
|
||||||
|
foreach ($toList as $addr) {
|
||||||
|
if (filter_var($addr, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$mail->addAddress($addr);
|
||||||
|
$added++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($added === 0) {
|
||||||
|
// Final fallback: send to FROM address
|
||||||
|
$mail->addAddress($fromEmail, $fromName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DKIM (optional)
|
||||||
|
if (!empty($cfg['dkim_domain']) && !empty($cfg['dkim_selector']) && !empty($cfg['dkim_private_key_path'])) {
|
||||||
|
$mail->DKIM_domain = $cfg['dkim_domain'];
|
||||||
|
$mail->DKIM_selector = $cfg['dkim_selector'];
|
||||||
|
$mail->DKIM_private = $cfg['dkim_private_key_path'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail->isHTML(true);
|
||||||
|
$mail->Subject = $subject;
|
||||||
|
$safeName = htmlspecialchars($name, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||||
|
$safeEmail = htmlspecialchars($email, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||||
|
$safeBody = nl2br(htmlspecialchars($body, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'));
|
||||||
|
$mail->Body = "<p><strong>Name:</strong> {$safeName}</p><p><strong>Email:</strong> {$safeEmail}</p><hr>{$safeBody}";
|
||||||
|
$mail->AltBody = "Name: {$name}\nEmail: {$email}\n\n{$body}";
|
||||||
|
|
||||||
|
$ok = $mail->send();
|
||||||
|
return [ 'success' => $ok ];
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return [ 'success' => false, 'error' => 'PHPMailer error: ' . $e->getMessage() ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function sendViaNativeMail(array $cfg, string $name, string $email, string $body, $to, string $subject)
|
||||||
|
{
|
||||||
|
// NOTE: Native mail() requires a local MTA; attachments are not handled here for simplicity.
|
||||||
|
// Resolve destination: dynamic $to (string or array) -> MAIL_TO -> MAIL_FROM
|
||||||
|
$dest = null;
|
||||||
|
if ($to) {
|
||||||
|
if (is_array($to)) {
|
||||||
|
$dest = implode(',', array_filter($to, fn($a)=>filter_var($a, FILTER_VALIDATE_EMAIL)));
|
||||||
|
} elseif (is_string($to)) {
|
||||||
|
$dest = $to;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$dest) {
|
||||||
|
$dest = getenv('MAIL_TO') ?: ($cfg['from_email'] ?? 'root@localhost');
|
||||||
|
}
|
||||||
|
$headers = [];
|
||||||
|
$fromEmail = $cfg['from_email'] ?? 'no-reply@localhost';
|
||||||
|
$fromName = $cfg['from_name'] ?? 'App';
|
||||||
|
$headers[] = 'From: ' . sprintf('"%s" <%s>', $fromName, $fromEmail);
|
||||||
|
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$headers[] = 'Reply-To: ' . $email;
|
||||||
|
} elseif (!empty($cfg['reply_to'])) {
|
||||||
|
$headers[] = 'Reply-To: ' . $cfg['reply_to'];
|
||||||
|
}
|
||||||
|
$headers[] = 'MIME-Version: 1.0';
|
||||||
|
$headers[] = 'Content-Type: text/plain; charset=UTF-8';
|
||||||
|
|
||||||
|
$content = "Name: {$name}\nEmail: {$email}\n\n{$body}";
|
||||||
|
$ok = @mail($dest, $subject, $content, implode("\r\n", $headers));
|
||||||
|
if ($ok) return [ 'success' => true ];
|
||||||
|
return [ 'success' => false, 'error' => 'mail() failed or MTA not configured' ];
|
||||||
|
}
|
||||||
|
}
|
||||||
75
mail/config.php
Normal file
75
mail/config.php
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
// Mail configuration sourced from environment variables.
|
||||||
|
// No secrets are stored here; the file just maps env -> config array for MailService.
|
||||||
|
|
||||||
|
function env_val(string $key, $default = null) {
|
||||||
|
$v = getenv($key);
|
||||||
|
return ($v === false || $v === null || $v === '') ? $default : $v;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
// Supports simple KEY=VALUE lines; ignores quotes and comments.
|
||||||
|
function load_dotenv_if_needed(array $keys): void {
|
||||||
|
$missing = array_filter($keys, fn($k) => getenv($k) === false || getenv($k) === '');
|
||||||
|
if (empty($missing)) return;
|
||||||
|
static $loaded = false;
|
||||||
|
if ($loaded) return;
|
||||||
|
$envPath = realpath(__DIR__ . '/../../.env'); // executor/.env
|
||||||
|
if ($envPath && is_readable($envPath)) {
|
||||||
|
$lines = @file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [];
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
if ($line[0] === '#' || trim($line) === '') continue;
|
||||||
|
if (!str_contains($line, '=')) continue;
|
||||||
|
[$k, $v] = array_map('trim', explode('=', $line, 2));
|
||||||
|
// Strip potential surrounding quotes
|
||||||
|
$v = trim($v, "\"' ");
|
||||||
|
// Do not override existing env
|
||||||
|
if ($k !== '' && (getenv($k) === false || getenv($k) === '')) {
|
||||||
|
putenv("{$k}={$v}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$loaded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
load_dotenv_if_needed([
|
||||||
|
'MAIL_TRANSPORT','SMTP_HOST','SMTP_PORT','SMTP_SECURE','SMTP_USER','SMTP_PASS',
|
||||||
|
'MAIL_FROM','MAIL_FROM_NAME','MAIL_REPLY_TO','DKIM_DOMAIN','DKIM_SELECTOR','DKIM_PRIVATE_KEY_PATH'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$transport = env_val('MAIL_TRANSPORT', 'smtp');
|
||||||
|
$smtp_host = env_val('SMTP_HOST');
|
||||||
|
$smtp_port = (int) env_val('SMTP_PORT', 587);
|
||||||
|
$smtp_secure = env_val('SMTP_SECURE', 'tls'); // tls | ssl | null
|
||||||
|
$smtp_user = env_val('SMTP_USER');
|
||||||
|
$smtp_pass = env_val('SMTP_PASS');
|
||||||
|
|
||||||
|
$from_email = env_val('MAIL_FROM', 'no-reply@localhost');
|
||||||
|
$from_name = env_val('MAIL_FROM_NAME', 'App');
|
||||||
|
$reply_to = env_val('MAIL_REPLY_TO');
|
||||||
|
|
||||||
|
$dkim_domain = env_val('DKIM_DOMAIN');
|
||||||
|
$dkim_selector = env_val('DKIM_SELECTOR');
|
||||||
|
$dkim_private_key_path = env_val('DKIM_PRIVATE_KEY_PATH');
|
||||||
|
|
||||||
|
return [
|
||||||
|
'transport' => $transport,
|
||||||
|
|
||||||
|
// SMTP
|
||||||
|
'smtp_host' => $smtp_host,
|
||||||
|
'smtp_port' => $smtp_port,
|
||||||
|
'smtp_secure' => $smtp_secure,
|
||||||
|
'smtp_user' => $smtp_user,
|
||||||
|
'smtp_pass' => $smtp_pass,
|
||||||
|
|
||||||
|
// From / Reply-To
|
||||||
|
'from_email' => $from_email,
|
||||||
|
'from_name' => $from_name,
|
||||||
|
'reply_to' => $reply_to,
|
||||||
|
|
||||||
|
// DKIM (optional)
|
||||||
|
'dkim_domain' => $dkim_domain,
|
||||||
|
'dkim_selector' => $dkim_selector,
|
||||||
|
'dkim_private_key_path' => $dkim_private_key_path,
|
||||||
|
];
|
||||||
Loading…
x
Reference in New Issue
Block a user