diff --git a/cron.php b/cron.php
index cb437d50..ff77c041 100644
--- a/cron.php
+++ b/cron.php
@@ -2,12 +2,6 @@
SMTPDebug = 3; // 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
-
- //Recipients
- $mail->setFrom($config_invoice_from_email, $config_invoice_from_name);
- $mail->addAddress("$contact_email", "$contact_name"); // Add a recipient
-
- // Content
- $mail->isHTML(true); // Set email format to HTML
-
- $mail->Subject = "Overdue Invoice $invoice_prefix$invoice_number";
- $mail->Body = "Hello $contact_name,
According to our records, we have not received payment for invoice $invoice_prefix$invoice_number. Please submit your payment as soon as possible. If you have any questions please contact us at $company_phone.
+ $subject = "Overdue Invoice $invoice_prefix$invoice_number";
+ $body = "Hello $contact_name,
According to our records, we have not received payment for invoice $invoice_prefix$invoice_number. Please submit your payment as soon as possible. If you have any questions please contact us at $company_phone.
Please view the details of the invoice 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
To view your invoice click here
~
$company_name
Billing Department
$config_invoice_from_email
$company_phone";
- $mail->send();
+ $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
+ $config_invoice_from_email, $config_invoice_from_name,
+ $contact_email, $contact_name,
+ $subject, $body);
- mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Overdue Invoice', history_created_at = NOW(), history_invoice_id = $invoice_id, company_id = $company_id");
+ if ($mail === true) {
+ mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Overdue Invoice', history_created_at = NOW(), history_invoice_id = $invoice_id, company_id = $company_id");
+ } else {
+ mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Failed to send Overdue Invoice', history_created_at = NOW(), history_invoice_id = $invoice_id, company_id = $company_id");
- }catch (Exception $e) {
- echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
- mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Failed to send Overdue Invoice', history_created_at = NOW(), history_invoice_id = $new_invoice_id, company_id = $company_id");
- } //End Mail Try
+ mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', notification_timestamp = NOW(), company_id = $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 = $company_id");
+ }
}
@@ -361,42 +338,26 @@ while($row = mysqli_fetch_array($sql_companies)){
$contact_name = $row['contact_name'];
$contact_email = $row['contact_email'];
- $mail = new PHPMailer(true);
- try{
+ $subject = "Invoice $invoice_prefix$invoice_number";
+ $body = "Hello $contact_name,
Please view the details of the invoice 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 click here
~
$company_name
Billing Department
$config_invoice_from_email
$company_phone";
- //Mail Server Settings
+ $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
+ $config_invoice_from_email, $config_invoice_from_name,
+ $contact_email, $contact_name,
+ $subject, $body);
- $mail->SMTPDebug = 3; // 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
+ if ($mail === true) {
+ mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Invoice!', history_created_at = NOW(), history_invoice_id = $new_invoice_id, company_id = $company_id");
+ mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent', invoice_updated_at = NOW(), invoice_client_id = $client_id WHERE invoice_id = $new_invoice_id");
- //Recipients
- $mail->setFrom($config_invoice_from_email, $config_invoice_from_name);
- $mail->addAddress("$contact_email", "$contact_name"); // Add a recipient
+ } else {
+ mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Draft', history_description = 'Cron Failed to send Invoice!', history_created_at = NOW(), history_invoice_id = $new_invoice_id, company_id = $company_id");
- // Content
- $mail->isHTML(true); // Set email format to HTML
+ mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', notification_timestamp = NOW(), company_id = $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 = $company_id");
+ }
- $mail->Subject = "Invoice $invoice_prefix$invoice_number";
- $mail->Body = "Hello $contact_name,
Please view the details of the invoice 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 click here
~
$company_name
Billing Department
$config_invoice_from_email
$company_phone";
-
- $mail->send();
-
- mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Invoice!', history_created_at = NOW(), history_invoice_id = $new_invoice_id, company_id = $company_id");
-
- //Update Invoice Status to Sent
- mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent', invoice_updated_at = NOW(), invoice_client_id = $client_id WHERE invoice_id = $new_invoice_id");
-
- }catch (Exception $e) {
- echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
- mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Draft', history_description = 'Cron Failed to send Invoice!', history_created_at = NOW(), history_invoice_id = $new_invoice_id, company_id = $company_id");
- } //End Mail Try
} //End if Autosend is on
} //End Recurring Invoices Loop
//Send Alert to inform Cron was run
diff --git a/functions.php b/functions.php
index c67203bf..5305086a 100644
--- a/functions.php
+++ b/functions.php
@@ -3,6 +3,14 @@
// Role check failed wording
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
+use PHPMailer\PHPMailer\PHPMailer;
+use PHPMailer\PHPMailer\Exception;
+
function keygen()
{
$chars = "abcdefghijklmnopqrstuvwxyz";
@@ -504,4 +512,46 @@ function validateAccountantRole(){
}
}
+// Send a single email to a single recipient
+function sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port, $from_email, $from_name, $to_email, $to_name, $subject, $body){
+
+ $mail = new PHPMailer(true);
+
+ try{
+ // Mail Server Settings
+ $mail->SMTPDebug = 0; // No Debugging
+ $mail->isSMTP(); // Set mailer to use SMTP
+ $mail->Host = $config_smtp_host; // Specify SMTP server
+ $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
+
+ //Recipients
+ $mail->setFrom($from_email, $from_name);
+ $mail->addAddress("$to_email", "$to_name"); // Add a recipient
+
+ // Content
+ $mail->isHTML(true); // Set email format to HTML
+ $mail->Subject = "$subject"; // Subject
+ $mail->Body = "$body"; // Content
+
+ // Attachments - todo
+ //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
+ //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
+
+ // Send
+ $mail->send();
+
+ // Return true if this was successful
+ return true;
+ }
+
+ catch(Exception $e){
+ // If we couldn't send the message return the error so we can log it
+ return "Message not sent. Mailer Error: {$mail->ErrorInfo}";
+ }
+}
+
?>
diff --git a/portal/login_reset.php b/portal/login_reset.php
index d883cc20..6351f6e6 100644
--- a/portal/login_reset.php
+++ b/portal/login_reset.php
@@ -4,12 +4,6 @@
* Password reset page
*/
-// Initiate PHPMailer
-require_once("../plugins/PHPMailer/src/PHPMailer.php");
-require_once("../plugins/PHPMailer/src/SMTP.php");
-use PHPMailer\PHPMailer\PHPMailer;
-use PHPMailer\PHPMailer\Exception;
-
$session_company_id = 1;
require_once('../config.php');
require_once('../functions.php');
@@ -62,37 +56,23 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
mysqli_query($mysqli, "UPDATE contacts SET contact_password_reset_token = '$token' WHERE contact_id = $id LIMIT 1");
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Contact', log_action = 'Modify', log_description = 'Sent a portal password reset e-mail for $email.', log_ip = '$ip', log_user_agent = '$user_agent', log_created_at = NOW(), log_client_id = $client, company_id = $company");
- // Send email
- $mail = new PHPMailer(true);
- try{
- //Mail Server Settings
- $mail->SMTPDebug = false; // No debug output as client facing
- $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
+ // Send reset email
+ $subject = "Password reset for $company_name ITFlow Portal";
+ $body = "Hello, $name
Someone (probably you) has requested a new password for your account on $company_name's ITFlow Client Portal.
Please click here to reset your password.
Alternatively, copy and paste this URL into your browser: $url
If you didn't request this change, you can safely ignore this email.
~
$company_name
Support Department
$config_mail_from_email";
- //Recipients
- $mail->setFrom($config_mail_from_email, $config_mail_from_name);
- $mail->addAddress("$email", "$name"); // Add user as recipient
+ $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
+ $config_mail_from_email, $config_mail_from_name,
+ $email, $name,
+ $subject, $body);
- // Content
- $mail->isHTML(true); // Set email format to HTML
-
- $mail->Subject = "Password reset for $company_name ITFlow Portal";
- $mail->Body = "Hello, $name
Someone (probably you) has requested a new password for your account on $company_name's ITFlow Client Portal.
Please click here to reset your password.
Alternatively, copy and paste this URL into your browser: $url
If you didn't request this change, you can safely ignore this email.
~
$company_name
Support Department
$config_mail_from_email";
- $mail->send();
+ // Error handling
+ if ($mail !== true) {
+ mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $email', notification_timestamp = NOW(), company_id = $company");
+ mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $email regarding $subject. $mail', company_id = $company");
}
- catch(Exception $e){
- echo "Message could not be sent. Please contact $company_name.";
- mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Contact', log_action = 'Modify', log_description = 'FAILED to send a portal password reset e-mail for $email due to PHP Mailer error.', log_ip = '$ip', log_user_agent = '$user_agent', log_created_at = NOW(), log_client_id = $client, company_id = $company");
- exit();
- }
- //End Mail IF Try-Catch
+
+ //End Mail IF
} else {
sleep(rand(2, 4)); // Mimic the e-mail send delay even if email is invalid to help prevent user enumeration
}
@@ -129,36 +109,20 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Contact', log_action = 'Modify', log_description = 'Reset portal password for $email.', log_ip = '$ip', log_user_agent = '$user_agent', log_created_at = NOW(), log_client_id = $client, company_id = $company");
// Send confirmation email
- $mail = new PHPMailer(true);
+ $subject = "Password reset confirmation for $company_name ITFlow Portal";
+ $body = "Hello, $name
Your password for your account on $company_name's ITFlow Client Portal was successfully reset. You should be all set!
If you didn't reset your password, please get in touch ASAP.
~
$company_name
Support Department
$config_mail_from_email";
- try{
- //Mail Server Settings
- $mail->SMTPDebug = false; // No debug output as client facing
- $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
- //Recipients
- $mail->setFrom($config_mail_from_email, $config_mail_from_name);
- $mail->addAddress("$email", "$name"); // Add user as recipient
+ $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
+ $config_mail_from_email, $config_mail_from_name,
+ $email, $name,
+ $subject, $body);
- // Content
- $mail->isHTML(true); // Set email format to HTML
-
- $mail->Subject = "Password reset confirmation for $company_name ITFlow Portal";
- $mail->Body = "Hello, $name
Your password for your account on $company_name's ITFlow Client Portal was successfully reset. You should be all set!
If you didn't reset your password, please get in touch ASAP.
~
$company_name
Support Department
$config_mail_from_email";
- $mail->send();
+ // Error handling
+ if ($mail !== true) {
+ mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $email', notification_timestamp = NOW(), company_id = $company");
+ mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $email regarding $subject. $mail', company_id = $company");
}
- catch(Exception $e){
- echo "Message could not be sent. Please contact $company_name.";
- mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Contact', log_action = 'Modify', log_description = 'FAILED to send a password reset e-mail for $email due to PHP Mailer error.', log_ip = '$ip', log_user_agent = '$user_agent', log_created_at = NOW(), log_client_id = $client, company_id = $company");
- exit();
- }
- //End Mail IF Try-Catch
// Redirect to login page
$_SESSION['login_message'] = "Password reset successfully!";
diff --git a/post.php b/post.php
index 755efe87..eb97e1f6 100644
--- a/post.php
+++ b/post.php
@@ -4,13 +4,6 @@ include("config.php");
include("functions.php");
include("check_login.php");
-require("plugins/PHPMailer/src/PHPMailer.php");
-require("plugins/PHPMailer/src/SMTP.php");
-
-// Initiate PHPMailer
-use PHPMailer\PHPMailer\PHPMailer;
-use PHPMailer\PHPMailer\Exception;
-
if(isset($_POST['change_records_per_page'])){
$_SESSION['records_per_page'] = intval($_POST['change_records_per_page']);
@@ -124,31 +117,22 @@ if(isset($_POST['add_user'])){
// Send e-mail to client if public update & email is setup
if(isset($_POST['send_email']) && !empty($config_smtp_host)){
- $mail = new PHPMailer(true);
-
- //Mail Server Settings
- $mail->SMTPDebug = 2; // 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
+ $subject = "Your new $session_company_name ITFlow account";
+ $body = "Hello, $name
An ITFlow account has been setup for you. Please change your password upon login.
Username: $email
Password: $_POST[password]
Login URL: $config_base_url
~
$session_company_name
Support Department
$config_ticket_from_email";
- //Recipients
- $mail->setFrom($config_ticket_from_email, $config_ticket_from_name);
- $mail->addAddress("$email", "$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,
+ $email, $name,
+ $subject, $body);
- // Content
- $mail->isHTML(true); // Set email format to HTML
+ if ($mail !== true) {
+ mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $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 $email regarding $subject. $mail', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
+ }
- $mail->Subject = "Your new $session_company_name ITFlow account";
- $mail->Body = "Hello, $name
An ITFlow account has been setup for you. Please change your password upon login.
Username: $email
Password: $_POST[password]
Login URL: $config_base_url
~
$session_company_name
Support Department
$config_ticket_from_email";
- $mail->send();
}
- //Logging
+ // Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'User', log_action = 'Create', log_description = '$session_name created user $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
$_SESSION['alert_message'] = "User $name created";
@@ -855,33 +839,17 @@ if(isset($_POST['test_email_smtp'])){
validateAdminRole();
$email = strip_tags(mysqli_real_escape_string($mysqli,$_POST['email']));
+ $subject = "Hi'ya there Chap";
+ $body = "Hello there Chap ;) Don't worry this won't hurt a bit, it's just a test";
- $mail = new PHPMailer(true);
+ $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
+ $config_mail_from_email, $config_mail_from_name,
+ $email, $email,
+ $subject, $body);
- //Mail Server Settings
-
- $mail->SMTPDebug = 2; // 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
-
- //Recipients
- $mail->setFrom($config_mail_from_email, $config_mail_from_name);
- $mail->addAddress("$email"); // Add a recipient
-
- // Content
- $mail->isHTML(true); // Set email format to HTML
-
- $mail->Subject = "Hi'ya there Chap";
- $mail->Body = "Hello there Chap ;) Don't worry this won't hurt a bit, it's just a test";
-
- if($mail->send()){
+ if($mail === true){
$_SESSION['alert_message'] = "Test email sent successfully";
- }else{
+ } else {
$_SESSION['alert_type'] = "error";
$_SESSION['alert_message'] = "Test email failed";
}
@@ -1611,40 +1579,23 @@ if(isset($_POST['add_event'])){
$company_website = $row['company_website'];
$company_logo = $row['company_logo'];
- $mail = new PHPMailer(true);
+ $subject = "New Calendar Event";
+ $body = "Hello $contact_name,
A calendar event has been scheduled: $title at $start
~
$company_name
$company_phone";
- try {
+ $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
+ $config_mail_from_email, $config_mail_from_name,
+ $contact_email, $contact_name,
+ $subject, $body);
- //Mail Server Settings
-
- $mail->SMTPDebug = 2; // 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
-
- //Recipients
- $mail->setFrom($config_mail_from_email, $config_mail_from_name);
- $mail->addAddress("$contact_email", "$contact_name"); // Add a recipient
-
- // Content
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = "New Calendar Event";
- $mail->Body = "Hello $contact_name,
A calendar event has been scheduled: $title at $start
~
$company_name
$company_phone";
-
- $mail->send();
- echo 'Message has been sent';
-
- } catch (Exception $e) {
- echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
+ // Logging for email (success/fail)
+ if ($mail === true) {
+ mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Calendar_Event', log_action = 'Email', log_description = '$session_name emailed event $event_title to $contact_name from client $client_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
+ } else {
+ 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', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
}
- //Logging
- mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Calendar_Event', log_action = 'Email', log_description = '$session_name emailed event $event_title to $contact_name from client $client_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
- }
+ } // End mail IF
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Calendar_Event', log_action = 'Create', log_description = '$session_name created event $title in calendar', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
@@ -1688,40 +1639,24 @@ if(isset($_POST['edit_event'])){
$company_website = $row['company_website'];
$company_logo = $row['company_logo'];
- $mail = new PHPMailer(true);
- try {
+ $subject = "Calendar Event Rescheduled";
+ $body = "Hello $contact_name,
A calendar event has been rescheduled: $title at $start
~
$company_name
$company_phone";
- //Mail Server Settings
+ $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
+ $config_mail_from_email, $config_mail_from_name,
+ $contact_email, $contact_name,
+ $subject, $body);
- $mail->SMTPDebug = 2; // 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
-
- //Recipients
- $mail->setFrom($config_mail_from_email, $config_mail_from_name);
- $mail->addAddress("$contact_email", "$contact_name"); // Add a recipient
-
- // Content
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = "Calendar Event Rescheduled";
- $mail->Body = "Hello $contact_name,
A calendar event has been rescheduled: $title at $start
~
$company_name
$company_phone";
-
- $mail->send();
- echo 'Message has been sent';
-
- } catch (Exception $e) {
- echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
+ // Logging for email (success/fail)
+ if ($mail === true) {
+ mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Calendar_Event', log_action = 'Email', log_description = '$session_name Emailed modified event $title to $client_name email $client_email', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
+ } else {
+ 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', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
}
- //Logging
- mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Calendar_Event', log_action = 'Email', log_description = '$session_name Emailed modified event $title to $client_name email $client_email', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
- }
+ } // End mail IF
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Calendar_Event', log_action = 'Modify', log_description = '$session_name modified event $title in calendar', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
@@ -3104,51 +3039,33 @@ if(isset($_GET['email_quote'])){
$company_website = $row['company_website'];
$company_logo = $row['company_logo'];
- $mail = new PHPMailer(true);
+ $subject = "Quote [$quote_scope]";
+ $body = "Hello $contact_name,
Thank you for your inquiry, we are pleased to provide you with the following estimate.
$quote_scope
Total Cost: " . numfmt_format_currency($currency_format, $quote_amount, $quote_currency_code) . "
View and accept your estimate online here
~
$company_name
Sales
$config_quote_from_email
$company_phone";
- //Mail Server Settings
+ $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
+ $config_quote_from_email, $config_quote_from_name,
+ $contact_email, $contact_name,
+ $subject, $body);
- //$mail->SMTPDebug = 2; // 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
+ // Logging
+ if ($mail === true) {
+ mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Emailed Quote!', history_quote_id = $quote_id, company_id = $session_company_id");
+ mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Quote', log_action = 'Email', log_description = '$quote_id emailed to $contact_email', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
- //Recipients
- $mail->setFrom($config_quote_from_email, $config_quote_from_name);
- $mail->addAddress("$contact_email", "$contact_name"); // Add a recipient
+ $_SESSION['alert_message'] = "Quote has been sent";
+ } else {
+ 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', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
- // Attachments
- //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
- //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
- //$mail->addAttachment("uploads/$quote_date-$config_company_name-Quote$quote_number.pdf"); // Optional name
-
- // Content
- $mail->isHTML(true); // Set email format to HTML
-
- $mail->Subject = "Quote [$quote_scope]";
- $mail->Body = "Hello $contact_name,
Thank you for your inquiry, we are pleased to provide you with the following estimate.
$quote_scope
Total Cost: " . numfmt_format_currency($currency_format, $quote_amount, $quote_currency_code) . "
View and accept your estimate online here
~
$company_name
Sales
$config_quote_from_email
$company_phone";
-
- $mail->send();
- echo 'Message has been sent';
-
- mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Emailed Quote!', history_quote_id = $quote_id, company_id = $session_company_id");
+ $_SESSION['alert_type'] = "error";
+ $_SESSION['alert_message'] = "Error sending quote";
+ }
//Don't change the status to sent if the status is anything but draft
if($quote_status == 'Draft'){
-
mysqli_query($mysqli,"UPDATE quotes SET quote_status = 'Sent' WHERE quote_id = $quote_id AND company_id = $session_company_id");
-
}
- //Logging
- mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Quote', log_action = 'Email', log_description = '$quote_id emailed to $contact_email', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
-
- $_SESSION['alert_message'] = "Quote has been sent";
-
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
@@ -3608,71 +3525,55 @@ if(isset($_POST['add_payment'])){
if($invoice_balance == 0){
$invoice_status = "Paid";
if($email_receipt == 1){
- $mail = new PHPMailer(true);
- //Mail Server Settings
- //$mail->SMTPDebug = 2; // 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
+ $subject = "Payment Recieved - Invoice $invoice_prefix$invoice_number";
+ $body = "Hello $contact_name,
We have recieved your payment in the amount of " . numfmt_format_currency($currency_format, $amount, $invoice_currency_code) . " for invoice $invoice_prefix$invoice_number. Please keep this email as a receipt for your records.
Amount: " . numfmt_format_currency($currency_format, $amount, $invoice_currency_code) . "
Balance: " . numfmt_format_currency($currency_format, $invoice_balance, $invoice_currency_code) . "
Thank you for your business!
~
$company_name
Billing Department
$config_invoice_from_email
$company_phone";
- //Recipients
- $mail->setFrom($config_invoice_from_email, $config_invoice_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_invoice_from_email, $config_invoice_from_name,
+ $contact_email, $contact_name,
+ $subject, $body);
- // Content
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = "Payment Recieved - Invoice $invoice_prefix$invoice_number";
- $mail->Body = "Hello $contact_name,
We have recieved your payment in the amount of " . numfmt_format_currency($currency_format, $amount, $invoice_currency_code) . " for invoice $invoice_prefix$invoice_number. Please keep this email as a receipt for your records.
Amount: " . numfmt_format_currency($currency_format, $amount, $invoice_currency_code) . "
Balance: " . numfmt_format_currency($currency_format, $invoice_balance, $invoice_currency_code) . "
Thank you for your business!
~
$company_name
Billing Department
$config_invoice_from_email
$company_phone";
-
- $mail->send();
-
- if(!$mail->send()){
- $_SESSION['alert_message'] .= "Mailer Error ";
- mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Email Receipt Failed!', history_invoice_id = $invoice_id, company_id = $session_company_id");
- }else{
+ // Email Logging
+ if ($mail === true) {
$_SESSION['alert_message'] .= "Email receipt sent ";
+
mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Emailed Receipt!', history_invoice_id = $invoice_id, company_id = $session_company_id");
+ } else {
+ mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Email Receipt Failed!', history_invoice_id = $invoice_id, company_id = $session_company_id");
+ $_SESSION['alert_message'] .= "Mailer Error ";
+
+ 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', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
}
}
}else{
$invoice_status = "Partial";
if($email_receipt == 1){
- $mail = new PHPMailer(true);
- //Mail Server Settings
- //$mail->SMTPDebug = 2; // 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
+ $subject = "Partial Payment Recieved - Invoice $invoice_prefix$invoice_number";
+ $body = "Hello $contact_name,
We have recieved partial payment in the amount of " . numfmt_format_currency($currency_format, $amount, $invoice_currency_code) . " and it has been applied to invoice $invoice_prefix$invoice_number. Please keep this email as a receipt for your records.
Amount: " . numfmt_format_currency($currency_format, $amount, $invoice_currency_code) . "
Balance: " . numfmt_format_currency($currency_format, $invoice_balance, $invoice_currency_code) . "
Thank you for your business!
~
$company_name
Billing Department
$config_invoice_from_email
$company_phone";
- //Recipients
- $mail->setFrom($config_invoice_from_email, $config_invoice_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_invoice_from_email, $config_invoice_from_name,
+ $contact_email, $contact_name,
+ $subject, $body);
- // Content
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = "Partial Payment Recieved - Invoice $invoice_prefix$invoice_number";
- $mail->Body = "Hello $contact_name,
We have recieved partial payment in the amount of " . numfmt_format_currency($currency_format, $amount, $invoice_currency_code) . " and it has been applied to invoice $invoice_prefix$invoice_number. Please keep this email as a receipt for your records.
Amount: " . numfmt_format_currency($currency_format, $amount, $invoice_currency_code) . "
Balance: " . numfmt_format_currency($currency_format, $invoice_balance, $invoice_currency_code) . "
Thank you for your business!
~
$company_name
Billing Department
$config_invoice_from_email
$company_phone";
+ // Email Logging
+ if ($mail === true) {
+ $_SESSION['alert_message'] .= "Email receipt sent ";
- if(!$mail->send()){
- $_SESSION['alert_message'] .= "Mailer Error ";
- mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Email Receipt Failed!', history_invoice_id = $invoice_id, company_id = $session_company_id");
- }else{
- $_SESSION['alert_message'] .= "Email receipt sent ";
- mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Emailed Receipt!', history_invoice_id = $invoice_id, company_id = $session_company_id");
- }
+ mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Emailed Receipt!', history_invoice_id = $invoice_id, company_id = $session_company_id");
+ } else {
+ mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Email Receipt Failed!', history_invoice_id = $invoice_id, company_id = $session_company_id");
+ $_SESSION['alert_message'] .= "Mailer Error ";
+
+ 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', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
+ }
}
@@ -3788,54 +3689,40 @@ if(isset($_GET['email_invoice'])){
$balance = $invoice_amount - $amount_paid;
- $mail = new PHPMailer(true);
+ if($invoice_status == 'Paid') {
+ $subject = "Invoice $invoice_prefix$invoice_number Copy";
+ $body = "Hello $contact_name,
Please click on the link below to see your invoice marked paid.
Invoice Link
~
$company_name
Billing Department
$config_invoice_from_email
$company_phone";
- //Mail Server Settings
+ } else {
- //$mail->SMTPDebug = 2; // 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
-
- //Recipients
- $mail->setFrom($config_invoice_from_email, $config_invoice_from_name);
- $mail->addAddress("$contact_email", "$contact_name"); // Add a recipient
-
- // Content
- $mail->isHTML(true); // Set email format to HTML
-
- if($invoice_status == 'Paid'){
-
- $mail->Subject = "Invoice $invoice_prefix$invoice_number Copy";
- $mail->Body = "Hello $contact_name,
Please click on the link below to see your invoice marked paid.
Invoice Link
~
$company_name
Billing Department
$config_invoice_from_email
$company_phone";
-
- }else{
-
- $mail->Subject = "Invoice $invoice_prefix$invoice_number";
- $mail->Body = "Hello $contact_name,
Please view the details of the invoice below.
Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: " . numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code) . "
Balance Due: " . numfmt_format_currency($currency_format, $balance, $invoice_currency_code) . "
Due Date: $invoice_due
To view your invoice click here
~
$company_name
Billing Department
$config_invoice_from_email
$company_phone";
- //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
+ $subject = "Invoice $invoice_prefix$invoice_number";
+ $body = "Hello $contact_name,
Please view the details of the invoice below.
Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: " . numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code) . "
Balance Due: " . numfmt_format_currency($currency_format, $balance, $invoice_currency_code) . "
Due Date: $invoice_due
To view your invoice click here
~
$company_name
Billing Department
$config_invoice_from_email
$company_phone";
}
- if(!$mail->send()){
- $_SESSION['alert_type'] = "error";
- $_SESSION['alert_message'] = "Invoice Failed to send ";
- mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Email Invoice Failed', history_invoice_id = $invoice_id, company_id = $session_company_id");
- }else{
+ $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
+ $config_invoice_from_email, $config_invoice_from_name,
+ $contact_email, $contact_name,
+ $subject, $body);
+
+ if ($mail === true) {
$_SESSION['alert_message'] = "Invoice has been sent";
mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Emailed invoice', history_invoice_id = $invoice_id, company_id = $session_company_id");
//Don't chnage the status to sent if the status is anything but draft
if($invoice_status == 'Draft'){
- mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent' WHERE invoice_id = $invoice_id AND company_id = $session_company_id");
+ mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent' WHERE invoice_id = $invoice_id AND company_id = $session_company_id");
}
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Invoice', log_action = 'Email', log_description = 'Invoice $invoice_prefix$invoice_number emailed to $client_email', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
+ } else {
+ $_SESSION['alert_type'] = "error";
+ $_SESSION['alert_message'] = "Invoice Failed to send ";
+ mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Email Invoice Failed', history_invoice_id = $invoice_id, company_id = $session_company_id");
+
+ 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', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
}
header("Location: " . $_SERVER["HTTP_REFERER"]);
@@ -5880,33 +5767,20 @@ if(isset($_POST['add_ticket'])){
// Verify contact email is valid
if(filter_var($contact_email, FILTER_VALIDATE_EMAIL)){
- $mail = new PHPMailer(true);
- try{
- //Mail Server Settings
- $mail->SMTPDebug = 2; // 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
+ $subject = "Ticket created - [$ticket_prefix$ticket_number] - $subject";
+ $body = "#--itflow--#
Hello, $contact_name
A ticket regarding \"$subject\" has been created for you.
--------------------------------
$details--------------------------------
Ticket: $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,
+ $subject, $body);
- // Content
- $mail->isHTML(true); // Set email format to HTML
-
- $mail->Subject = "Ticket created - [$ticket_prefix$ticket_number] - $subject";
- $mail->Body = "#--itflow--#
Hello, $contact_name
A ticket regarding \"$subject\" has been created for you.
--------------------------------
$details--------------------------------
Ticket: $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', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
}
+
}
}
@@ -6158,36 +6032,21 @@ if(isset($_POST['add_ticket_reply'])){
if(filter_var($contact_email, FILTER_VALIDATE_EMAIL)){
- $mail = new PHPMailer(true);
+ $subject = "Ticket update - [$ticket_prefix$ticket_number] - $ticket_subject";
+ $body = "#--itflow--#
Hello, $contact_name
Your ticket regarding \"$ticket_subject\" has been updated.
--------------------------------
$ticket_reply--------------------------------
Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: $ticket_status
https://$config_base_url/portal/ticket.php?id=$ticket_id
~
$session_company_name
Support Department
$config_ticket_from_email
$company_phone";
- try{
- //Mail Server Settings
- $mail->SMTPDebug = 2; // 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
+ $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,
+ $subject, $body);
- //Recipients
- $mail->setFrom($config_ticket_from_email, $config_ticket_from_name);
- $mail->addAddress("$contact_email", "$contact_name"); // Add a recipient
-
- // Content
- $mail->isHTML(true); // Set email format to HTML
-
- $mail->Subject = "Ticket update - [$ticket_prefix$ticket_number] - $ticket_subject";
- $mail->Body = "#--itflow--#
Hello, $contact_name
Your ticket regarding \"$ticket_subject\" has been updated.
--------------------------------
$ticket_reply--------------------------------
Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: $ticket_status
https://$config_base_url/portal/ticket.php?id=$ticket_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', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
}
}
}
- //End Mail IF Try-Catch
+ //End Mail IF
// Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket Reply', log_action = 'Create', log_description = '$ticket_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
@@ -7050,35 +6909,29 @@ if(isset($_GET['force_recurring'])){
$company_email = $row['company_email'];
$company_website = $row['company_website'];
- $mail = new PHPMailer(true);
- //Mail Server Settings
+ // Email to client
- $mail->SMTPDebug = 2; // 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
+ $subject = "Invoice $invoice_prefix$invoice_number";
+ $body = "Hello $contact_name,
Please view the details of the invoice below.
Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: $$invoice_amount
Due Date: $invoice_due
To view your invoice click here
~
$company_name
$company_phone";
- //Recipients
- $mail->setFrom($config_invoice_from_email, $config_invoice_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_invoice_from_email, $config_invoice_from_name,
+ $contact_email, $contact_name,
+ $subject, $body);
- // Content
- $mail->isHTML(true); // Set email format to HTML
+ if ($mail === true) {
+ // Add send history
+ mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Force Emailed Invoice!', history_invoice_id = $new_invoice_id, company_id = $session_company_id");
- $mail->Subject = "Invoice $invoice_prefix$invoice_number";
- $mail->Body = "Hello $contact_name,
Please view the details of the invoice below.
Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: $$invoice_amount
Due Date: $invoice_due
To view your invoice click here
~
$company_name
$company_phone";
+ // Update Invoice Status to Sent
+ mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent', invoice_client_id = $client_id WHERE invoice_id = $new_invoice_id AND company_id = $session_company_id");
- $mail->send();
-
- mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Auto Emailed Invoice!', history_invoice_id = $new_invoice_id, company_id = $session_company_id");
-
- //Update Invoice Status to Sent
- mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent', invoice_client_id = $client_id WHERE invoice_id = $new_invoice_id AND company_id = $session_company_id");
+ } else {
+ // Error reporting
+ mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', notification_timestamp = NOW(), notification_client_id = $client_id, company_id = $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', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
+ }
} //End Recurring Invoices Loop