diff --git a/cron_ticket_email_parser.php b/cron_ticket_email_parser.php index 37e79be8..f4398063 100644 --- a/cron_ticket_email_parser.php +++ b/cron_ticket_email_parser.php @@ -36,12 +36,6 @@ if (!function_exists('imap_open')) { exit(); } -// Setup PHP Mailer -require("plugins/PHPMailer/src/PHPMailer.php"); -require("plugins/PHPMailer/src/SMTP.php"); -use PHPMailer\PHPMailer\PHPMailer; -use PHPMailer\PHPMailer\Exception; - // Prepare connection string with encryption (TLS/SSL/) $imap_mailbox = "$config_imap_host:$config_imap_port/imap/$config_imap_encryption"; @@ -178,34 +172,22 @@ if ($emails) { // E-mail client notification that ticket has been created - $mail = new PHPMailer(true); - try{ - //Mail Server Settings - $mail->SMTPDebug = 0; // Enable verbose debug output - $mail->isSMTP(); // Set mailer to use SMTP - $mail->Host = $config_smtp_host; // Specify main and backup SMTP servers - $mail->SMTPAuth = true; // Enable SMTP authentication - $mail->Username = $config_smtp_username; // SMTP username - $mail->Password = $config_smtp_password; // SMTP password - $mail->SMTPSecure = $config_smtp_encryption; // Enable TLS encryption, `ssl` also accepted - $mail->Port = $config_smtp_port; // TCP port to connect to + $email_subject = "Ticket created - [$config_ticket_prefix$ticket_number] - $subject"; + $email_body = "#--itflow--#

Hello, $contact_name

Thank you for your email. A ticket regarding \"$subject\" has been automatically created for you.

Ticket: $config_ticket_prefix$ticket_number
Subject: $subject
Status: Open
https://$config_base_url/portal/ticket.php?id=$id

~
$session_company_name
Support Department
$config_ticket_from_email
$company_phone"; - //Recipients - $mail->setFrom($config_ticket_from_email, $config_ticket_from_name); - $mail->addAddress("$contact_email", "$contact_name"); // Add a recipient + $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port, + $config_ticket_from_email, $config_ticket_from_name, + $contact_email, $contact_name, + $email_subject, $email_body); - // Content - $mail->isHTML(true); // Set email format to HTML - - $mail->Subject = "Ticket created - [$config_ticket_prefix$ticket_number] - $subject"; - $mail->Body = "#--itflow--#

Hello, $contact_name

Thank you for your email. A ticket regarding \"$subject\" has been automatically created for you.

Ticket: $config_ticket_prefix$ticket_number
Subject: $subject
Status: Open
https://$config_base_url/portal/ticket.php?id=$id

~
$session_company_name
Support Department
$config_ticket_from_email
$company_phone"; - $mail->send(); - } - catch(Exception $e){ - echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; + if ($mail !== true) { + mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', notification_timestamp = NOW(), company_id = $session_company_id"); + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail', company_id = $session_company_id"); } + + } else { // Couldn't match this against a specific client contact -- do nothing for now