Files
wms-app/app/setting/api/engine/test_smtp.php
T

25 lines
952 B
PHP

<?php
require_once __DIR__ . '/../../../session.php';
require_once '../../../assets/utils/db_auth.php';
require_once '../../../assets/utils/classes/SmtpManager.php';
if ($user_role !== 'owner') { http_response_code(403); exit(json_encode(['success' => 0, 'message' => 'Only the owner can modify this setting.'])); }
try {
$smtp = new SmtpManager($pdo1, $company_id, $method, $pinkey, $iv);
$to = trim((string)($data['test_email'] ?? ''));
$smtp->sendTest($to);
$answer['success'] = 1;
$answer['message'] = 'Test email sent to ' . htmlspecialchars($to) . '.';
} catch (Exception $e) {
$answer['message'] = $e->getMessage();
http_response_code(in_array($e->getMessage(), [
'Invalid recipient email address.',
'No SMTP configuration found. Please save your settings first.',
], true) ? 422 : 500);
}
exit(json_encode($answer));
?>