diff --git a/cron_ticket_email_parser.php b/cron_ticket_email_parser.php
index e4ba5fb7d..d6bd91880 100644
--- a/cron_ticket_email_parser.php
+++ b/cron_ticket_email_parser.php
@@ -7,7 +7,6 @@
/*
TODO:
- Process unregistered contacts/clients into an inbox to allow a ticket to be created/ignored
- - Better handle replying to closed tickets
- Support for authenticating with OAuth
- Separate Mailbox Account for tickets 2022-12-14 - JQ
@@ -23,6 +22,12 @@
// Get settings for the "default" company
require_once("get_settings.php");
+// Get company name & phone
+$sql = mysqli_query($mysqli, "SELECT company_name, company_phone FROM companies WHERE company_id = 1");
+$row = mysqli_fetch_array($sql);
+$company_name = $row['company_name'];
+$company_phone = formatPhoneNumber($row['company_phone']);
+
// Check setting enabled
if ($config_ticket_email_parse == 0) {
exit("Email Parser: Feature is not enabled - check Settings > Ticketing > Email-to-ticket parsing. See https://docs.itflow.org/ticket_email_parse -- Quitting..");
@@ -65,7 +70,7 @@
function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date, $subject, $message, $attachments) {
// Access global variables
- global $mysqli, $config_ticket_prefix, $config_ticket_client_general_notifications, $config_base_url, $config_ticket_from_name, $config_ticket_from_email, $config_smtp_host, $config_smtp_port, $config_smtp_encryption, $config_smtp_username, $config_smtp_password;
+ global $mysqli, $company_name, $company_phone, $config_ticket_prefix, $config_ticket_client_general_notifications, $config_base_url, $config_ticket_from_name, $config_ticket_from_email, $config_smtp_host, $config_smtp_port, $config_smtp_encryption, $config_smtp_username, $config_smtp_password, $allowed_extensions;
// Get the next Ticket Number and add 1 for the new ticket number
$ticket_number_sql = mysqli_fetch_array(mysqli_query($mysqli, "SELECT config_ticket_next_number FROM settings WHERE company_id = 1"));
@@ -94,7 +99,6 @@ function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date
$att_extension = strtolower(end($att_extarr));
// Check the extension is allowed
- global $allowed_extensions;
if (in_array($att_extension, $allowed_extensions)) {
// Setup directory for this ticket ID
@@ -119,12 +123,6 @@ function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date
}
- // Get company name & phone
- $sql = mysqli_query($mysqli, "SELECT company_name, company_phone FROM companies WHERE company_id = 1");
- $row = mysqli_fetch_array($sql);
- $company_phone = formatPhoneNumber($row['company_phone']);
- $company_name = $row['company_name'];
-
// E-mail client notification that ticket has been created
if ($config_ticket_client_general_notifications == 1) {
@@ -161,7 +159,7 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac
// Add email as a comment/reply to an existing ticket
// Access global variables
- global $mysqli, $config_ticket_prefix, $config_base_url, $config_ticket_from_name, $config_ticket_from_email, $config_smtp_host, $config_smtp_port, $config_smtp_encryption, $config_smtp_username, $config_smtp_password;
+ global $mysqli, $company_name, $company_phone, $config_ticket_prefix, $config_base_url, $config_ticket_from_name, $config_ticket_from_email, $config_smtp_host, $config_smtp_port, $config_smtp_encryption, $config_smtp_username, $config_smtp_password, $allowed_extensions;
// Set default reply type
$ticket_reply_type = 'Client';
@@ -187,9 +185,27 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac
$ticket_contact_email = $row['contact_email'];
$client_id = intval($row['ticket_client_id']);
- // Check ticket isn't closed
+ // Check ticket isn't closed - tickets can't be re-opened
if ($ticket_status == "Closed") {
mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Ticket', notification = 'Email parser: $from_email attempted to re-open ticket $config_ticket_prefix$ticket_number (ID $ticket_id) - check inbox manually to see email', notification_client_id = $client_id");
+
+ $email_subject = "Action required: This ticket is already closed";
+ $email_body = "Hi there,
You've tried to reply to a ticket that is closed - we won't see your response.
Please raise a new ticket by sending a fresh e-mail to our support address.
~
$company_name
Support Department
$config_ticket_from_email
$company_phone";
+
+ sendSingleEmail(
+ $config_smtp_host,
+ $config_smtp_username,
+ $config_smtp_password,
+ $config_smtp_encryption,
+ $config_smtp_port,
+ $config_ticket_from_email,
+ $config_ticket_from_name,
+ $from_email,
+ $from_email,
+ $email_subject,
+ $email_body
+ );
+
return false;
}
@@ -230,7 +246,6 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac
$att_extension = strtolower(end($att_extarr));
// Check the extension is allowed
- global $allowed_extensions;
if (in_array($att_extension, $allowed_extensions)) {
// Setup directory for this ticket ID