WebOrbiton
v1.0.0.0

StocketBase

44 lines · 1.4 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. if (count(get_included_files()) === 1) {
  6. http_response_code(403);
  7. exit;
  8. }
  9. ​
  10. require_once __DIR__ . '/../includes/mailer.php';
  11. ​
  12. if (!Auth::hasRoleAtLeast(Auth::ROLE_STORE_OWNER)) {
  13. $flashMessage = 'You do not have permission to send test emails.';
  14. $flashType = 'error';
  15. ​
  16. return;
  17. }
  18. ​
  19. $testRecipient = trim((string) ($currentUser['email'] ?? ''));
  20. ​
  21. if ($testRecipient === '' || filter_var($testRecipient, FILTER_VALIDATE_EMAIL) === false) {
  22. $flashMessage = 'Your team account has no valid email address on file — add one in Profile first.';
  23. $flashType = 'error';
  24. ​
  25. return;
  26. }
  27. ​
  28. $storeSettings = SiteFront::settings();
  29. $siteName = (string) ($storeSettings['site_name'] ?? 'StocketBase');
  30. $transport = (string) ($storeSettings['mail_transport'] ?? 'smtp');
  31. ​
  32. $html = '<p>This is a test email sent from the <strong>' . htmlspecialchars($siteName, ENT_QUOTES) . '</strong> email settings.</p>'
  33. . '<p>If you received this, your <strong>' . htmlspecialchars($transport, ENT_QUOTES) . '</strong> configuration is working.</p>';
  34. ​
  35. $sent = Mailer::send($testRecipient, 'Test email from ' . $siteName, $html);
  36. ​
  37. if ($sent) {
  38. $flashMessage = 'Test email sent to ' . $testRecipient . '.';
  39. $flashType = 'success';
  40. } else {
  41. $flashMessage = 'Could not send the test email — check the settings and the server error log for details.';
  42. $flashType = 'error';
  43. }
  44. ​