Files
wms-app/app/setting/api/engine/test_smtp.php
T
2026-05-20 10:17:02 +07:00

25 lines
807 B
PHP

<?php
session_start();
require '../../../assets/utils/db_auth.php';
require '../../../assets/utils/classes/SmtpManager.php';
require_role($user_role, ['owner', 'admin']);
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));
?>