From 2c51289d75037110ea9d6efd73bbec8e2879cbcd Mon Sep 17 00:00:00 2001 From: johnnyq Date: Wed, 22 Jan 2025 20:56:24 -0500 Subject: [PATCH] Remove mysqli connection vars when passing mail data to addToMailQueue Function --- ajax.php | 2 +- cron.php | 10 +++++----- cron_ticket_email_parser.php | 6 +++--- functions.php | 6 +++--- guest/guest_ajax.php | 2 -- guest/guest_footer.php | 2 -- guest/guest_pay_invoice_stripe.php | 2 +- guest/guest_post.php | 4 ++-- login.php | 4 ++-- portal/login_reset.php | 4 ++-- portal/portal_post.php | 6 +++--- post/admin/admin_settings_mail.php | 2 +- post/admin/admin_user.php | 2 +- post/user/contact.php | 2 +- post/user/event.php | 4 ++-- post/user/invoice.php | 12 ++++++------ post/user/profile.php | 6 +++--- post/user/quote.php | 2 +- post/user/ticket.php | 28 ++++++++++++++-------------- scripts/cron.php | 12 ++++++------ scripts/cron_ticket_email_parser.php | 6 +++--- 21 files changed, 60 insertions(+), 64 deletions(-) diff --git a/ajax.php b/ajax.php index c36bf475..085f0702 100644 --- a/ajax.php +++ b/ajax.php @@ -364,7 +364,7 @@ if (isset($_GET['share_generate_link'])) { ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); } diff --git a/cron.php b/cron.php index 9504a6b6..21434f9a 100644 --- a/cron.php +++ b/cron.php @@ -363,7 +363,7 @@ if (mysqli_num_rows($sql_scheduled_tickets) > 0) { } // Add to the mail queue - addToMailQueue($mysqli, $data); + addToMailQueue($data); // Set the next run date if ($frequency == "weekly") { @@ -487,7 +487,7 @@ if ($config_send_invoice_reminders == 1) {

Kindly review the invoice details mentioned below.

Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: " . numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code) . "
Due Date: $invoice_due
Over Due By: $day Days


To view your invoice, please click here.


--
$company_name - Billing
$config_invoice_from_email
$company_phone"; - $mail = addToMailQueue($mysqli, [ + $mail = addToMailQueue([ [ 'from' => $config_invoice_from_email, 'from_name' => $config_invoice_from_name, @@ -496,7 +496,7 @@ if ($config_send_invoice_reminders == 1) { 'subject' => $subject, 'body' => $body ] - ]); + ]); if ($mail === true) { mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Overdue Invoice', history_invoice_id = $invoice_id"); @@ -619,7 +619,7 @@ while ($row = mysqli_fetch_array($sql_recurring)) { $subject = "Invoice $invoice_prefix$invoice_number"; $body = "Hello $contact_name,

An invoice regarding \"$invoice_scope\" has been generated. Please view the details below.

Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: " . numfmt_format_currency($currency_format, $invoice_amount, $recurring_currency_code) . "
Due Date: $invoice_due


To view your invoice, please click here.


--
$company_name - Billing
$config_invoice_from_email
$company_phone"; - $mail = addToMailQueue($mysqli, [ + $mail = addToMailQueue([ [ 'from' => $config_invoice_from_email, 'from_name' => $config_invoice_from_name, @@ -666,7 +666,7 @@ while ($row = mysqli_fetch_array($sql_recurring)) { ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); } } //End if Autosend is on diff --git a/cron_ticket_email_parser.php b/cron_ticket_email_parser.php index e8b3e637..69daefbc 100644 --- a/cron_ticket_email_parser.php +++ b/cron_ticket_email_parser.php @@ -187,7 +187,7 @@ function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date ]; } - addToMailQueue($mysqli, $data); + addToMailQueue($data); // Custom action/notif handler customAction('ticket_create', $id); @@ -249,7 +249,7 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); return true; } @@ -319,7 +319,7 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); } } diff --git a/functions.php b/functions.php index 1bcc9349..fd27e6a9 100644 --- a/functions.php +++ b/functions.php @@ -5,9 +5,7 @@ DEFINE("WORDING_ROLECHECK_FAILED", "You are not permitted to do that!"); // PHP Mailer Libs require_once "plugins/PHPMailer/src/Exception.php"; - require_once "plugins/PHPMailer/src/PHPMailer.php"; - require_once "plugins/PHPMailer/src/SMTP.php"; // Initiate PHPMailer @@ -1029,7 +1027,9 @@ function generateReadablePassword($security_level) return $password; } -function addToMailQueue($mysqli, $data) { +function addToMailQueue($data) { + + global $mysqli; foreach ($data as $email) { $from = strval($email['from']); diff --git a/guest/guest_ajax.php b/guest/guest_ajax.php index efbc4868..9e01dfa7 100644 --- a/guest/guest_ajax.php +++ b/guest/guest_ajax.php @@ -10,9 +10,7 @@ require_once "../config.php"; // Set Timezone require_once "../inc_set_timezone.php"; - require_once "../functions.php"; - require_once "../rfc6238.php"; diff --git a/guest/guest_footer.php b/guest/guest_footer.php index bc6c1eb8..3db213d9 100644 --- a/guest/guest_footer.php +++ b/guest/guest_footer.php @@ -21,9 +21,7 @@ - - diff --git a/guest/guest_pay_invoice_stripe.php b/guest/guest_pay_invoice_stripe.php index 2b3065bb..0dc48126 100644 --- a/guest/guest_pay_invoice_stripe.php +++ b/guest/guest_pay_invoice_stripe.php @@ -342,7 +342,7 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent ]; } - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); // Email logging mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Emailed Receipt!', history_invoice_id = $invoice_id"); diff --git a/guest/guest_post.php b/guest/guest_post.php index 1cc9303c..97a33505 100644 --- a/guest/guest_post.php +++ b/guest/guest_post.php @@ -58,7 +58,7 @@ if (isset($_GET['accept_quote'], $_GET['url_key'])) { 'body' => $body, ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); } $_SESSION['alert_message'] = "Quote Accepted"; @@ -119,7 +119,7 @@ if (isset($_GET['decline_quote'], $_GET['url_key'])) { 'body' => $body, ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); } $_SESSION['alert_type'] = "danger"; diff --git a/login.php b/login.php index bdeb8190..87c48235 100644 --- a/login.php +++ b/login.php @@ -185,7 +185,7 @@ if (isset($_POST['login'])) { 'body' => $body ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); } // Logging @@ -262,7 +262,7 @@ if (isset($_POST['login'])) { 'body' => $body ] ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); } // HTML feedback for incorrect 2FA code diff --git a/portal/login_reset.php b/portal/login_reset.php index 002f3ae3..da679169 100644 --- a/portal/login_reset.php +++ b/portal/login_reset.php @@ -91,7 +91,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { 'body' => $body ] ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); // Error handling if ($mail !== true) { @@ -147,7 +147,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { ] ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); // Error handling if ($mail !== true) { diff --git a/portal/portal_post.php b/portal/portal_post.php index eab9c817..ae6f50fe 100644 --- a/portal/portal_post.php +++ b/portal/portal_post.php @@ -60,7 +60,7 @@ if (isset($_POST['add_ticket'])) { 'body' => $email_body, ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); } // Custom action/notif handler @@ -125,7 +125,7 @@ if (isset($_POST['add_ticket_comment'])) { ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); } @@ -628,7 +628,7 @@ if (isset($_GET['stripe_save_card'])) { ] ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); } diff --git a/post/admin/admin_settings_mail.php b/post/admin/admin_settings_mail.php index b36d3f42..d3e18010 100644 --- a/post/admin/admin_settings_mail.php +++ b/post/admin/admin_settings_mail.php @@ -105,7 +105,7 @@ if (isset($_POST['test_email_smtp'])) { 'body' => $body ] ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); if ($mail === true) { $_SESSION['alert_message'] = "Test email queued successfully! Check Admin > Mail queue"; diff --git a/post/admin/admin_user.php b/post/admin/admin_user.php index e3b0f2d8..5b095795 100644 --- a/post/admin/admin_user.php +++ b/post/admin/admin_user.php @@ -81,7 +81,7 @@ if (isset($_POST['add_user'])) { 'body' => $body ] ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); if ($mail !== true) { mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $email'"); diff --git a/post/user/contact.php b/post/user/contact.php index fa625666..63f3358d 100644 --- a/post/user/contact.php +++ b/post/user/contact.php @@ -201,7 +201,7 @@ if (isset($_POST['edit_contact'])) { 'body' => $body, ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); // Get Email ID for reference $email_id = mysqli_insert_id($mysqli); diff --git a/post/user/event.php b/post/user/event.php index de5bca54..0ee47441 100644 --- a/post/user/event.php +++ b/post/user/event.php @@ -94,7 +94,7 @@ if (isset($_POST['add_event'])) { 'body' => $body ] ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); // Logging for email (success/fail) if ($mail === true) { @@ -163,7 +163,7 @@ if (isset($_POST['edit_event'])) { 'body' => $body ] ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); // Logging for email (success/fail) if ($mail === true) { logAction("Calendar Event", "Email", "$session_name Emailed modified event $title to $contact_name email $contact_email", $client, $event_id); diff --git a/post/user/invoice.php b/post/user/invoice.php index 343e5907..efeda390 100644 --- a/post/user/invoice.php +++ b/post/user/invoice.php @@ -817,7 +817,7 @@ if (isset($_POST['add_payment'])) { // Add email to queue if (!empty($email)) { - addToMailQueue($mysqli, $email_data); + addToMailQueue($email_data); } // Get Email ID for reference @@ -852,7 +852,7 @@ if (isset($_POST['add_payment'])) { // Add email to queue if (!empty($email)) { - addToMailQueue($mysqli, $email_data); + addToMailQueue($email_data); } // Get Email ID for reference @@ -1031,7 +1031,7 @@ if (isset($_GET['add_payment_stripe'])) { ]; } - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); // Email Logging $email_id = mysqli_insert_id($mysqli); @@ -1326,7 +1326,7 @@ if (isset($_GET['email_invoice'])) { ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); // Get Email ID for reference $email_id = mysqli_insert_id($mysqli); @@ -1374,7 +1374,7 @@ if (isset($_GET['email_invoice'])) { } - addToMailQueue($mysqli, $data); + addToMailQueue($data); header("Location: " . $_SERVER["HTTP_REFERER"]); @@ -1563,7 +1563,7 @@ if (isset($_GET['force_recurring'])) { 'body' => $body ] ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); if ($mail === true) { // Add send history diff --git a/post/user/profile.php b/post/user/profile.php index 2b431729..7c011ba7 100644 --- a/post/user/profile.php +++ b/post/user/profile.php @@ -47,7 +47,7 @@ if (isset($_POST['edit_your_user_details'])) { 'body' => $body ] ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); } // Photo @@ -138,7 +138,7 @@ if (isset($_POST['edit_your_user_password'])) { 'body' => $body ] ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); } $new_password = password_hash($new_password, PASSWORD_DEFAULT); @@ -267,7 +267,7 @@ if (isset($_POST['disable_2fa'])){ 'body' => $body ] ]; - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); } // Logging diff --git a/post/user/quote.php b/post/user/quote.php index ac9b05ac..44cda583 100644 --- a/post/user/quote.php +++ b/post/user/quote.php @@ -502,7 +502,7 @@ if (isset($_GET['email_quote'])) { 'body' => $body, ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); // Update History mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Emailed Quote', history_quote_id = $quote_id"); diff --git a/post/user/ticket.php b/post/user/ticket.php index c53668d5..bd358d11 100644 --- a/post/user/ticket.php +++ b/post/user/ticket.php @@ -151,7 +151,7 @@ if (isset($_POST['add_ticket'])) { 'body' => $body ]; } - addToMailQueue($mysqli, $data); + addToMailQueue($data); // END EMAILING @@ -236,7 +236,7 @@ if (isset($_POST['edit_ticket'])) { ]; } - addToMailQueue($mysqli, $data); + addToMailQueue($data); } // Custom action/notif handler @@ -354,7 +354,7 @@ if (isset($_POST['edit_ticket_contact'])) { 'body' => $body ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); } // Custom action/notif handler @@ -431,7 +431,7 @@ if (isset($_POST['add_ticket_watcher'])) { ]; } - addToMailQueue($mysqli, $data); + addToMailQueue($data); } // Logging @@ -629,7 +629,7 @@ if (isset($_POST['assign_ticket'])) { 'body' => $body, ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); } } @@ -772,7 +772,7 @@ if (isset($_POST['bulk_assign_ticket'])) { 'body' => $body, ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); } } } @@ -999,7 +999,7 @@ if (isset($_POST['bulk_resolve_tickets'])) { 'body' => $body ]; } - addToMailQueue($mysqli, $data); + addToMailQueue($data); } // End Mail IF } // End Loop } // End Array Empty Check @@ -1136,7 +1136,7 @@ if (isset($_POST['bulk_ticket_reply'])) { 'body' => $body ]; } - addToMailQueue($mysqli, $data); + addToMailQueue($data); } //End Mail IF // Notification for assigned ticket user @@ -1452,7 +1452,7 @@ if (isset($_POST['add_ticket_reply'])) { 'body' => $body ]; } - addToMailQueue($mysqli, $data); + addToMailQueue($data); } //End Mail IF @@ -1700,7 +1700,7 @@ if (isset($_GET['resolve_ticket'])) { 'body' => $body ]; } - addToMailQueue($mysqli, $data); + addToMailQueue($data); } //End Mail IF @@ -1794,7 +1794,7 @@ if (isset($_GET['close_ticket'])) { 'body' => $body ]; } - addToMailQueue($mysqli, $data); + addToMailQueue($data); } //End Mail IF @@ -2103,7 +2103,7 @@ if (isset($_GET['force_recurring_ticket'])) { } // Add to the mail queue - addToMailQueue($mysqli, $data); + addToMailQueue($data); // Set the next run date (based on the scheduled date, rather than now, so things keep their schedule) $dt_old_next_scheduled_date = new DateTime($old_next_scheduled_date); @@ -2367,7 +2367,7 @@ if (isset($_POST['edit_ticket_schedule'])) { } // Send - $response = addToMailQueue($mysqli, $data); + $response = addToMailQueue($data); // Update ticket reply $ticket_reply_note = "Ticket scheduled for $email_datetime " . (boolval($onsite) ? '(onsite).' : '(remote).'); @@ -2519,7 +2519,7 @@ if (isset($_GET['cancel_ticket_schedule'])) { } // Send email(s) - addToMailQueue($mysqli, $data); + addToMailQueue($data); // Update ticket reply $ticket_reply_note = "Ticket schedule cancelled."; diff --git a/scripts/cron.php b/scripts/cron.php index dbb3e0f6..d87a0b9b 100644 --- a/scripts/cron.php +++ b/scripts/cron.php @@ -390,7 +390,7 @@ if (mysqli_num_rows($sql_scheduled_tickets) > 0) { } // Add to the mail queue - addToMailQueue($mysqli, $data); + addToMailQueue($data); // Set the next run date if ($frequency == "weekly") { @@ -514,7 +514,7 @@ if ($config_send_invoice_reminders == 1) {

Kindly review the invoice details mentioned below.

Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: " . numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code) . "
Due Date: $invoice_due
Over Due By: $day Days


To view your invoice, please click here.


--
$company_name - Billing
$config_invoice_from_email
$company_phone"; - $mail = addToMailQueue($mysqli, [ + $mail = addToMailQueue([ [ 'from' => $config_invoice_from_email, 'from_name' => $config_invoice_from_name, @@ -523,7 +523,7 @@ if ($config_send_invoice_reminders == 1) { 'subject' => $subject, 'body' => $body ] - ]); + ]); if ($mail === true) { mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Overdue Invoice', history_invoice_id = $invoice_id"); @@ -647,7 +647,7 @@ while ($row = mysqli_fetch_array($sql_recurring)) { $subject = "Invoice $invoice_prefix$invoice_number"; $body = "Hello $contact_name,

An invoice regarding \"$invoice_scope\" has been generated. Please view the details below.

Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: " . numfmt_format_currency($currency_format, $invoice_amount, $recurring_currency_code) . "
Due Date: $invoice_due


To view your invoice, please click here.


--
$company_name - Billing
$config_invoice_from_email
$company_phone"; - $mail = addToMailQueue($mysqli, [ + $mail = addToMailQueue([ [ 'from' => $config_invoice_from_email, 'from_name' => $config_invoice_from_name, @@ -694,7 +694,7 @@ while ($row = mysqli_fetch_array($sql_recurring)) { ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); } } //End if Autosend is on @@ -792,7 +792,7 @@ while ($row = mysqli_fetch_array($sql_recurring)) { ]; } - $mail = addToMailQueue($mysqli, $data); + $mail = addToMailQueue($data); // Email Logging $email_id = mysqli_insert_id($mysqli); diff --git a/scripts/cron_ticket_email_parser.php b/scripts/cron_ticket_email_parser.php index 146305b0..80008d75 100644 --- a/scripts/cron_ticket_email_parser.php +++ b/scripts/cron_ticket_email_parser.php @@ -187,7 +187,7 @@ function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date ]; } - addToMailQueue($mysqli, $data); + addToMailQueue($data); // Custom action/notif handler customAction('ticket_create', $id); @@ -249,7 +249,7 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); return true; } @@ -319,7 +319,7 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac ] ]; - addToMailQueue($mysqli, $data); + addToMailQueue($data); } }