25 lines
807 B
PHP
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));
|
|
?>
|