Mail queue & tickets

- Allow cancelling emails
- Adjust wording of ticket scheduling emails
This commit is contained in:
Marcus Hill 2024-02-24 11:06:55 +00:00
parent da54b125c3
commit 1e8fbddcbd
4 changed files with 45 additions and 25 deletions

View File

@ -133,11 +133,16 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<td>
<button class="btn btn-sm btn-secondary" data-toggle="modal" data-target="#viewEmailModal<?php echo $email_id; ?>"><i class="fas fa-fw fa-eye"></i></button>
<?php if($email_attempts > 3 && $email_status == 2) { ?>
<a class="btn btn-sm btn-success" href="post.php?send_failed_mail=<?php echo $email_id; ?>"><i class="fas fa-fw fa-paper-plane"></i></a>
<!-- Show force resend if all retries have failed -->
<?php if ($email_status == 2 && $email_attempts > 3) { ?>
<a class="btn btn-sm btn-success" href="post.php?send_failed_mail=<?php echo $email_id; ?>"><i class="fas fa-fw fa-paper-plane"></i></a>
<?php } ?>
<!-- Allow cancelling a message if it hasn't yet been picked up (e.g. stuck/bugged) -->
<?php if ($email_status == 0) { ?>
<a class="btn btn-sm btn-danger confirm-link" href="post.php?cancel_mail=<?php echo $email_id; ?>"><i class="fas fa-fw fa-trash"></i></a>
<?php } ?>
</td>
</tr>

View File

@ -53,7 +53,7 @@ file_put_contents($lock_file_path, "Locked");
// Process Mail Queue
// Email Status:
// Email Status:
// 0 Queued
// 1 Sending
// 2 Failed
@ -102,20 +102,20 @@ if (mysqli_num_rows($sql_queue) > 0) {
);
if ($mail !== true) {
// Update Message
// Update Message - Failure
mysqli_query($mysqli, "UPDATE email_queue SET email_status = 2, email_failed_at = NOW(), email_attempts = 1 WHERE email_id = $email_id");
mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $email_recipient_logging'");
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $email_recipient_logging regarding $email_subject_logging. $mail'");
} else {
// Update Message
// Update Message - Success
mysqli_query($mysqli, "UPDATE email_queue SET email_status = 3, email_sent_at = NOW(), email_attempts = 1 WHERE email_id = $email_id");
}
}
}
}
//
//
// Get Mail that failed to send and attempt to send Failed Mail up to 4 times every 30 mins
$sql_failed_queue = mysqli_query($mysqli, "SELECT * FROM email_queue WHERE email_status = 2 AND email_attempts < 4 AND email_failed_at < NOW() + INTERVAL 30 MINUTE");

View File

@ -151,7 +151,7 @@ if (isset($_POST['test_email_smtp'])) {
validateCSRFToken($_POST['csrf_token']);
validateAdminRole();
$test_email = intval($_POST['test_email']);
if($test_email == 1) {
$email_from = sanitizeInput($config_mail_from_email);
@ -328,7 +328,7 @@ if (isset($_POST['edit_theme_settings'])) {
if (isset($_POST['edit_favicon_settings'])) {
validateCSRFToken($_POST['csrf_token']);
validateAdminRole();
// Check to see if a file is attached
@ -451,7 +451,7 @@ if (isset($_POST['edit_integrations_settings'])) {
if (isset($_POST['edit_ai_settings'])) {
validateCSRFToken($_POST['csrf_token']);
validateAdminRole();
$provider = sanitizeInput($_POST['provider']);
@ -538,10 +538,10 @@ if (isset($_GET['send_failed_mail'])) {
$email_id = intval($_GET['send_failed_mail']);
mysqli_query($mysqli,"UPDATE email_queue SET email_attempts = 3 WHERE email_id = $email_id");
mysqli_query($mysqli,"UPDATE email_queue SET email_status = 0, email_attempts = 3 WHERE email_id = $email_id");
// Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Email', log_action = 'Send', log_description = '$session_name attempted to force send email queue id: $email_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Email', log_action = 'Send', log_description = '$session_name attempted to force send email queue id: $email_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, log_entity_id = $email_id");
$_SESSION['alert_message'] = "Email Force Sent, give it a minute to resend";
@ -549,6 +549,23 @@ if (isset($_GET['send_failed_mail'])) {
}
if (isset($_GET['cancel_mail'])) {
validateTechRole();
$email_id = intval($_GET['cancel_mail']);
mysqli_query($mysqli,"UPDATE email_queue SET email_status = 2, email_attempts = 99, email_failed_at = NOW() WHERE email_id = $email_id");
// Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Email', log_action = 'Cancel', log_description = '$session_name canceled send email queue id: $email_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, log_entity_id = $email_id");
$_SESSION['alert_message'] = "Email cancelled and marked as failed.";
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
if (isset($_GET['download_database'])) {
validateCSRFToken($_GET['csrf_token']);

View File

@ -1473,10 +1473,10 @@ if (isset($_POST['edit_ticket_schedule'])) {
mysqli_query(
$mysqli,
"UPDATE tickets SET
ticket_schedule = '$schedule',
ticket_onsite = '$onsite',
ticket_status = 'Scheduled'
WHERE ticket_id = $ticket_id"
ticket_schedule = '$schedule',
ticket_onsite = '$onsite',
ticket_status = 'Scheduled'
WHERE ticket_id = $ticket_id"
);
@ -1499,7 +1499,6 @@ if (isset($_POST['edit_ticket_schedule'])) {
WHERE ticket_id = $ticket_id
");
$row = mysqli_fetch_array($sql);
$client_id = intval($row['ticket_client_id']);
@ -1577,7 +1576,7 @@ if (isset($_POST['edit_ticket_schedule'])) {
'body' => mysqli_escape_string($mysqli, nullable_htmlentities("<div class='header'>
Hello,
</div>
Your ticket regarding $ticket_subject has been scheduled for $email_datetime.
The ticket regarding $ticket_subject has been scheduled for $email_datetime.
<br><br>
<a href='https://$config_base_url/portal/ticket.php?id=$ticket_id' class='link-button'>$ticket_link</a>
<br><br>
@ -1585,7 +1584,7 @@ if (isset($_POST['edit_ticket_schedule'])) {
<br><br>
<strong>Ticket:</strong> $ticket_prefix$ticket_number<br>
<strong>Subject:</strong> $ticket_subject<br>
<strong>Portal:</strong> <a href='https://$config_base_url/portal/ticket.php?id=$ticket_id'>Access your ticket here</a>
<strong>Portal:</strong> <a href='https://$config_base_url/portal/ticket.php?id=$ticket_id'>Access the ticket here</a>
<br><br>
<div class='footer'>
~<br>
@ -1630,7 +1629,6 @@ if (isset($_POST['edit_ticket_schedule'])) {
header("Location: calendar_events.php");
}
exit;
}
if (isset($_GET['cancel_ticket_schedule'])) {
@ -1686,7 +1684,7 @@ if (isset($_GET['cancel_ticket_schedule'])) {
'body' => mysqli_escape_string($mysqli, "<div class='header'>
Hello, $contact_name
</div>
Your ticket regarding $ticket_subject has been cancelled.
Scheduled work for your ticket regarding $ticket_subject has been cancelled.
<br><br>
<a href='https://$config_base_url/portal/ticket.php?id=$ticket_id' class='link-button'>Access your ticket here</a>
<br><br>
@ -1713,7 +1711,7 @@ if (isset($_GET['cancel_ticket_schedule'])) {
'recipient' => $user_email,
'recipient_name' => $user_name,
'subject' => "Ticket Schedule Cancelled - [$ticket_prefix$ticket_number] - $ticket_subject",
'body' => "Hello, " . $user_name . "<br><br>The ticket regarding $ticket_subject has been cancelled.<br><br>--------------------------------<br><a href=\"https://$config_base_url/ticket.php?id=$ticket_id\">$ticket_link</a><br>--------------------------------<br><br>Please do not reply to this email. <br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Portal: https://$config_base_url/ticket.php?id=$ticket_id<br><br>~<br>$session_company_name<br>Support Department<br>$config_ticket_from_email",
'body' => "Hello, " . $user_name . "<br><br>Scheduled work for the ticket regarding $ticket_subject has been cancelled.<br><br>--------------------------------<br><a href=\"https://$config_base_url/ticket.php?id=$ticket_id\">$ticket_link</a><br>--------------------------------<br><br>Please do not reply to this email. <br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Portal: https://$config_base_url/ticket.php?id=$ticket_id<br><br>~<br>$session_company_name<br>Support Department<br>$config_ticket_from_email",
'cal_str' => $cal_str
]
];
@ -1731,7 +1729,7 @@ if (isset($_GET['cancel_ticket_schedule'])) {
'body' => mysqli_escape_string($mysqli, nullable_htmlentities("<div class='header'>
Hello,
</div>
Your ticket regarding $ticket_subject has been cancelled.
Scheduled work for the ticket regarding $ticket_subject has been cancelled.
<br><br>
<a href='https://$config_base_url/portal/ticket.php?id=$ticket_id' class='link-button'>$ticket_link</a>
<br><br>
@ -1739,7 +1737,7 @@ if (isset($_GET['cancel_ticket_schedule'])) {
<br><br>
<strong>Ticket:</strong> $ticket_prefix$ticket_number<br>
<strong>Subject:</strong> $ticket_subject<br>
<strong>Portal:</strong> <a href='https://$config_base_url/portal/ticket.php?id=$ticket_id'>Access your ticket here</a>
<strong>Portal:</strong> <a href='https://$config_base_url/portal/ticket.php?id=$ticket_id'>Access the ticket here</a>
<br><br>
<div class='footer'>
~<br>