Initial version
This commit is contained in:
commit
b634080078
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_33959');
|
||||||
|
define('DB_USER', 'app_33959');
|
||||||
|
define('DB_PASS', '48b525e6-f0ac-4022-bdfe-88c92d2d6b94');
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
237
index.php
Normal file
237
index.php
Normal file
@ -0,0 +1,237 @@
|
|||||||
|
<?php
|
||||||
|
$message_sent = null;
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['contact_form'])) {
|
||||||
|
require_once __DIR__ . '/mail/MailService.php';
|
||||||
|
$name = filter_var($_POST['name'] ?? '', FILTER_SANITIZE_STRING);
|
||||||
|
$email = filter_var($_POST['email'] ?? '', FILTER_SANITIZE_EMAIL);
|
||||||
|
$message = filter_var($_POST['message'] ?? '', FILTER_SANITIZE_STRING);
|
||||||
|
|
||||||
|
if (!empty($name) && !empty($email) && !empty($message) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
// The recipient is determined by MailService, using MAIL_TO from .env
|
||||||
|
$res = MailService::sendContactMessage($name, $email, $message, null, 'Contact Form Submission');
|
||||||
|
if (!empty($res['success'])) {
|
||||||
|
$message_sent = true;
|
||||||
|
} else {
|
||||||
|
$message_sent = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$message_sent = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!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?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<!-- Navbar -->
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-transparent fixed-top">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand fw-bold" href="#">Ava Reed</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<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="#testimonials">Testimonials</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="#contact">Contact</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Hero Section -->
|
||||||
|
<header class="vh-100 d-flex align-items-center text-center text-white" style="background: url('https://picsum.photos/seed/ava-hero/1600/900') no-repeat center center; background-size: cover;">
|
||||||
|
<div class="container" style="background-color: rgba(0,0,0,0.5); padding: 2rem; border-radius: 1rem;">
|
||||||
|
<h1 class="display-4 fw-bold">Design & Development by Ava Reed.</h1>
|
||||||
|
<p class="lead my-4">Crafting elegant and effective digital solutions.</p>
|
||||||
|
<a href="#work" class="btn btn-primary btn-lg mx-2">View My Work</a>
|
||||||
|
<a href="#contact" class="btn btn-outline-light btn-lg mx-2">Contact Me</a>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<!-- Work Gallery -->
|
||||||
|
<section id="work" class="section">
|
||||||
|
<div class="container">
|
||||||
|
<h2 class="text-center mb-5">My Work</h2>
|
||||||
|
<div class="text-center mb-4">
|
||||||
|
<button type="button" class="btn btn-outline-primary active" data-filter="all">All</button>
|
||||||
|
<button type="button" class="btn btn-outline-primary" data-filter="web">Web Development</button>
|
||||||
|
<button type="button" class="btn btn-outline-primary" data-filter="uiux">UI/UX Design</button>
|
||||||
|
<button type="button" class="btn btn-outline-primary" data-filter="branding">Brand Identity</button>
|
||||||
|
</div>
|
||||||
|
<div class="row g-4 portfolio-container">
|
||||||
|
<?php
|
||||||
|
$projects = [
|
||||||
|
['category' => 'web', 'title' => 'Corporate Website Redesign'],
|
||||||
|
['category' => 'uiux', 'title' => 'Mobile App UI/UX'],
|
||||||
|
['category' => 'branding', 'title' => 'Startup Branding'],
|
||||||
|
['category' => 'uiux', 'title' => 'E-commerce Platform Design'],
|
||||||
|
['category' => 'web', 'title' => 'Portfolio Website'],
|
||||||
|
['category' => 'branding', 'title' => 'Logo & Identity Pack'],
|
||||||
|
];
|
||||||
|
$i = 1;
|
||||||
|
foreach ($projects as $project): ?>
|
||||||
|
<div class="col-md-6 col-lg-4 portfolio-item" data-category="<?php echo $project['category']; ?>">
|
||||||
|
<div class="card">
|
||||||
|
<img src="https://picsum.photos/seed/ava-work-<?php echo $i; ?>/600/400" class="card-img-top" alt="A sample of Ava Reed's design and development work.">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title"><?php echo $project['title']; ?></h5>
|
||||||
|
<p class="card-text">A brief description of the project, its goals, and the technologies used.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php $i++; endforeach; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Services -->
|
||||||
|
<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="card p-4 mb-4">
|
||||||
|
<i class="bi bi-palette-fill fs-1 text-primary mb-3"></i>
|
||||||
|
<h4>UI/UX Design</h4>
|
||||||
|
<p>Creating intuitive and beautiful user interfaces that provide a seamless user experience.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card p-4 mb-4">
|
||||||
|
<i class="bi bi-code-slash fs-1 text-primary mb-3"></i>
|
||||||
|
<h4>Web Development</h4>
|
||||||
|
<p>Building responsive, high-performance websites from the ground up.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card p-4 mb-4">
|
||||||
|
<i class="bi bi-vector-pen fs-1 text-primary mb-3"></i>
|
||||||
|
<h4>Brand Identity</h4>
|
||||||
|
<p>Developing strong and memorable brand identities that tell a story.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- About -->
|
||||||
|
<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/ava-avatar/256/256" class="img-fluid rounded-circle mb-4" alt="A portrait of Ava Reed.">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<h2 class="mb-4">About Me</h2>
|
||||||
|
<p class="lead">I'm Ava Reed, a passionate and creative designer and developer with a knack for building things that are both beautiful and functional. With over 5 years of experience, I help clients bring their ideas to life.</p>
|
||||||
|
<p>My approach is collaborative and user-centric, focusing on creating digital experiences that not only look good but also solve real-world problems and are a joy to use.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Testimonials -->
|
||||||
|
<section id="testimonials" class="section bg-light">
|
||||||
|
<div class="container">
|
||||||
|
<h2 class="text-center mb-5">What My Clients Say</h2>
|
||||||
|
<div class="row g-4">
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<img src="https://picsum.photos/seed/client-1/100/100" class="rounded-circle mb-3" alt="Client 1">
|
||||||
|
<p class="card-text fst-italic">"Ava is a true professional. The final product exceeded all our expectations. Her attention to detail is second to none."</p>
|
||||||
|
<footer class="blockquote-footer mt-3">John Doe, CEO of ExampleCorp</footer>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<img src="https://picsum.photos/seed/client-2/100/100" class="rounded-circle mb-3" alt="Client 2">
|
||||||
|
<p class="card-text fst-italic">"Working with Ava was a fantastic experience. She is not only a talented developer but also a great communicator."</p>
|
||||||
|
<footer class="blockquote-footer mt-3">Jane Smith, Marketing Director at Creative Inc.</footer>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<img src="https://picsum.photos/seed/client-3/100/100" class="rounded-circle mb-3" alt="Client 3">
|
||||||
|
<p class="card-text fst-italic">"The website Ava built for us is both beautiful and highly functional. We've seen a significant increase in user engagement."</p>
|
||||||
|
<footer class="blockquote-footer mt-3">Sam Wilson, Founder of TechStart</footer>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Contact Form -->
|
||||||
|
<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-lg-8">
|
||||||
|
<form action="index.php#contact" method="POST" class="needs-validation" novalidate>
|
||||||
|
<input type="hidden" name="contact_form" value="1">
|
||||||
|
|
||||||
|
<?php if ($message_sent === true): ?>
|
||||||
|
<div class="alert alert-success" role="alert">
|
||||||
|
Thank you! Your message has been sent successfully.
|
||||||
|
</div>
|
||||||
|
<?php elseif ($message_sent === false): ?>
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
Sorry, there was an error sending your message. Please try again later.
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<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 your message.</div>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary btn-lg">Send Message</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Footer -->
|
||||||
|
<footer class="py-5 bg-dark text-white text-center">
|
||||||
|
<div class="container">
|
||||||
|
<div class="mb-3">
|
||||||
|
<a href="#" class="text-white mx-2"><i class="bi bi-linkedin fs-4"></i></a>
|
||||||
|
<a href="#" class="text-white mx-2"><i class="bi bi-github fs-4"></i></a>
|
||||||
|
<a href="#" class="text-white mx-2"><i class="bi bi-dribbble fs-4"></i></a>
|
||||||
|
</div>
|
||||||
|
<p class="mb-0">© <?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?v=<?php echo time(); ?>"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
236
mail/MailService.php
Normal file
236
mail/MailService.php
Normal file
@ -0,0 +1,236 @@
|
|||||||
|
<?php
|
||||||
|
// Minimal mail service for the workspace app (VM).
|
||||||
|
// Usage:
|
||||||
|
// require_once __DIR__ . '/MailService.php';
|
||||||
|
// // Generic:
|
||||||
|
// MailService::sendMail($to, $subject, $htmlBody, $textBody = null, $opts = []);
|
||||||
|
// // Contact form helper:
|
||||||
|
// MailService::sendContactMessage($name, $email, $message, $to = null, $subject = 'New contact form');
|
||||||
|
|
||||||
|
class MailService
|
||||||
|
{
|
||||||
|
// Universal mail sender (no attachments by design)
|
||||||
|
public static function sendMail($to, string $subject, string $htmlBody, ?string $textBody = null, array $opts = [])
|
||||||
|
{
|
||||||
|
$cfg = self::loadConfig();
|
||||||
|
|
||||||
|
$autoload = __DIR__ . '/../vendor/autoload.php';
|
||||||
|
if (file_exists($autoload)) {
|
||||||
|
require_once $autoload;
|
||||||
|
}
|
||||||
|
if (!class_exists('PHPMailer\\PHPMailer\\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';
|
||||||
|
}
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||||
|
return [ 'success' => false, 'error' => 'PHPMailer not available' ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$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 = $opts['from_email'] ?? ($cfg['from_email'] ?? 'no-reply@localhost');
|
||||||
|
$fromName = $opts['from_name'] ?? ($cfg['from_name'] ?? 'App');
|
||||||
|
$mail->setFrom($fromEmail, $fromName);
|
||||||
|
if (!empty($opts['reply_to']) && filter_var($opts['reply_to'], FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$mail->addReplyTo($opts['reply_to']);
|
||||||
|
} elseif (!empty($cfg['reply_to'])) {
|
||||||
|
$mail->addReplyTo($cfg['reply_to']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recipients
|
||||||
|
$toList = [];
|
||||||
|
if ($to) {
|
||||||
|
if (is_string($to)) $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) { $mail->addAddress($fromEmail, $fromName); }
|
||||||
|
|
||||||
|
foreach ((array)($opts['cc'] ?? []) as $cc) { if (filter_var($cc, FILTER_VALIDATE_EMAIL)) $mail->addCC($cc); }
|
||||||
|
foreach ((array)($opts['bcc'] ?? []) as $bcc){ if (filter_var($bcc, FILTER_VALIDATE_EMAIL)) $mail->addBCC($bcc); }
|
||||||
|
|
||||||
|
// Optional DKIM
|
||||||
|
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;
|
||||||
|
$mail->Body = $htmlBody;
|
||||||
|
$mail->AltBody = $textBody ?? strip_tags($htmlBody);
|
||||||
|
$ok = $mail->send();
|
||||||
|
return [ 'success' => $ok ];
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return [ 'success' => false, 'error' => 'PHPMailer error: ' . $e->getMessage() ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
// Enable verbose debug output
|
||||||
|
$mail->SMTPDebug = 0;
|
||||||
|
$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)
|
||||||
|
{
|
||||||
|
$opts = ['reply_to' => $email];
|
||||||
|
$html = nl2br(htmlspecialchars($body, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'));
|
||||||
|
return self::sendMail($to, $subject, $html, $body, $opts);
|
||||||
|
}
|
||||||
|
}
|
||||||
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