accounting workflows
This commit is contained in:
@@ -1,57 +1,24 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes/SmtpManager.php';
|
||||
|
||||
require_role($user_role, ['owner', 'admin']);
|
||||
|
||||
try {
|
||||
|
||||
$to = trim($data['test_email'] ?? '');
|
||||
|
||||
if (!filter_var($to, FILTER_VALIDATE_EMAIL)) {
|
||||
$answer['message'] = 'Invalid recipient email address.';
|
||||
http_response_code(422);
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
// Fetch from_name / channel_name for the sender display
|
||||
$sth = $pdo1->prepare("
|
||||
SELECT from_name FROM company_smtp
|
||||
WHERE company_id = :company_id LIMIT 1
|
||||
");
|
||||
$sth->execute([':company_id' => $company_id]);
|
||||
db_check($sth, $answer);
|
||||
$row = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$row) {
|
||||
$answer['message'] = 'No SMTP configuration found. Please save your settings first.';
|
||||
http_response_code(422);
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$channel_name = $row['from_name'] ?: 'WMS System';
|
||||
|
||||
// Use existing mailer — it reads company_smtp via pdo1 automatically
|
||||
require_once $include_url . 'assets/utils/module/mailer.php';
|
||||
|
||||
$mailer = new mailer(['pdo1' => $pdo1]);
|
||||
$mailer->send_email([
|
||||
'company_id' => $company_id,
|
||||
'smtp' => [], // empty = mailer reads from company_smtp
|
||||
'to' => $to,
|
||||
'subject' => 'SMTP Test — WMS',
|
||||
'message' => "This is a test email from your WMS SMTP configuration.\n\nIf you received this, your SMTP settings are working correctly.",
|
||||
'channel_name' => $channel_name,
|
||||
'key' => $pinkey,
|
||||
]);
|
||||
|
||||
$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'] = 'Failed to send test email: ' . $e->getMessage();
|
||||
http_response_code(500);
|
||||
$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));
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user