v1.0.0.1
StocketBase
- <?php
-
- declare(strict_types=1);
-
- if (count(get_included_files()) === 1) {
- http_response_code(403);
- exit;
- }
-
- require_once __DIR__ . '/../includes/mailer.php';
-
- if (!Auth::hasRoleAtLeast(Auth::ROLE_STORE_OWNER)) {
- $flashMessage = 'You don\'t have access to test emails.';
- $flashType = 'error';
-
- return;
- }
-
- $testRecipient = trim((string) ($currentUser['email'] ?? ''));
-
- if ($testRecipient === '' || filter_var($testRecipient, FILTER_VALIDATE_EMAIL) === false) {
- $flashMessage = 'Your account doesn\'t have an email address yet. Ask the Super Admin to add one.';
- $flashType = 'error';
-
- return;
- }
-
- $storeSettings = SiteFront::settings();
- $siteName = (string) ($storeSettings['site_name'] ?? 'StocketBase');
- $transport = (string) ($storeSettings['mail_transport'] ?? 'smtp');
-
- $html = '<p>This is a test email sent from the <strong>' . htmlspecialchars($siteName, ENT_QUOTES) . '</strong> email settings.</p>'
- . '<p>If you received this, your <strong>' . htmlspecialchars($transport, ENT_QUOTES) . '</strong> configuration is working.</p>';
-
- $sent = Mailer::send($testRecipient, 'Test email from ' . $siteName, $html);
-
- if ($sent) {
- $flashMessage = 'Test email sent to ' . $testRecipient . '. Check your inbox.';
- $flashType = 'success';
- } else {
- $flashMessage = 'The test email didn\'t go out. Check your email settings and try again.';
- $flashType = 'error';
- }
-