From 6038b22f0a8f744bf36b86a2e1c756c62e687300 Mon Sep 17 00:00:00 2001 From: Brady Miller Date: Sun, 1 Jul 2018 00:16:29 -0700 Subject: [PATCH] phpmailer new version bug fix --- controllers/C_Prescription.class.php | 2 + interface/drugs/dispense_drug.php | 1 + interface/drugs/drugs.inc.php | 12 ++-- library/direct_message_check.inc | 2 + .../patient/fwk/libs/verysimple/Email/Mailer.php | 78 +++++++++++----------- 5 files changed, 52 insertions(+), 43 deletions(-) diff --git a/controllers/C_Prescription.class.php b/controllers/C_Prescription.class.php index 9727c2c51..31a484467 100644 --- a/controllers/C_Prescription.class.php +++ b/controllers/C_Prescription.class.php @@ -16,6 +16,8 @@ require_once($GLOBALS['fileroot'] . "/library/classes/Prescription.class.php"); require_once($GLOBALS['fileroot'] . "/library/registry.inc"); require_once($GLOBALS['fileroot'] . "/library/amc.php"); +use PHPMailer\PHPMailer\PHPMailer; + class C_Prescription extends Controller { diff --git a/interface/drugs/dispense_drug.php b/interface/drugs/dispense_drug.php index 033d3cb96..bea870205 100644 --- a/interface/drugs/dispense_drug.php +++ b/interface/drugs/dispense_drug.php @@ -12,6 +12,7 @@ require_once("drugs.inc.php"); require_once("$srcdir/options.inc.php"); use OpenEMR\Services\FacilityService; +use PHPMailer\PHPMailer\PHPMailer; $facilityService = new FacilityService(); diff --git a/interface/drugs/drugs.inc.php b/interface/drugs/drugs.inc.php index 27d088623..aba5cfe3f 100644 --- a/interface/drugs/drugs.inc.php +++ b/interface/drugs/drugs.inc.php @@ -9,9 +9,11 @@ // Modified 7-2009 by BM in order to migrate using the form, // unit, route, and interval lists with the // functions in openemr/library/options.inc.php . -// These lists are based on the constants found in the +// These lists are based on the constants found in the // openemr/library/classes/Prescription.class.php file. +use PHPMailer\PHPMailer\PHPMailer; + // Decision was made in June 2013 that a sale line item in the Fee Sheet may // come only from the specified warehouse. Set this to false if the decision // is reversed. @@ -82,7 +84,7 @@ function sellDrug( "FROM drugs WHERE drug_id = ?", array($drug_id)); $allow_combining = $rowdrug['allow_combining']; $dispensable = $rowdrug['dispensable']; - + if (!$dispensable) { // Non-dispensable is a much simpler case and does not touch inventory. if ($testonly) { @@ -98,7 +100,7 @@ function sellDrug( ); return $sale_id; } - + // Combining is never allowed for prescriptions and will not work with // dispense_drug.php. if ($prescription_id) { @@ -187,7 +189,7 @@ function sellDrug( // $qty_left, if positive, is the amount requested that could not be allocated. return $qty_left <= 0; } - + if ($bad_lot_list) { send_drug_email( "Possible lot destruction needed", @@ -283,7 +285,7 @@ function sellDrug( // TBD: If the above is un-commented, fix it to handle the case of // $GLOBALS['gbl_min_max_months'] being true. *******************************************************************/ - + // If combining is allowed then $sale_id will be just the last inserted ID, // and it serves only to indicate that everything worked. Otherwise there // can be only one inserted row and this is its ID. diff --git a/library/direct_message_check.inc b/library/direct_message_check.inc index 15f435fcb..c5289e840 100644 --- a/library/direct_message_check.inc +++ b/library/direct_message_check.inc @@ -28,6 +28,8 @@ require_once(dirname(__FILE__) . "/pnotes.inc"); require_once(dirname(__FILE__) . "/documents.php"); require_once(dirname(__FILE__) . "/gprelations.inc.php"); +use PHPMailer\PHPMailer\PHPMailer; + /** * Connect to a phiMail Direct Messaging server */ diff --git a/portal/patient/fwk/libs/verysimple/Email/Mailer.php b/portal/patient/fwk/libs/verysimple/Email/Mailer.php index c5f47b8cd..b0c41649a 100644 --- a/portal/patient/fwk/libs/verysimple/Email/Mailer.php +++ b/portal/patient/fwk/libs/verysimple/Email/Mailer.php @@ -8,6 +8,8 @@ require_once("phpmailer/class.phpmailer.php"); require_once("EmailMessage.php"); require_once("Recipient.php"); +use PHPMailer\PHPMailer\PHPMailer; + define("MAILER_RESULT_FAIL", 0); define("MAILER_RESULT_OK", 1); @@ -34,7 +36,7 @@ class Mailer var $AuthPassword; var $Host; var $LangPath; - + /** * Constructor initializes the mailer object and prepares it for mailing * @@ -49,7 +51,7 @@ class Mailer function __construct($method = MAILER_METHOD_SENDMAIL, $path = "/usr/sbin/sendmail") { $pair = explode("@", $path); - + if (count($pair) > 1) { $this->Path = $pair [1]; $userpass = explode(":", $pair [0], 2); @@ -58,13 +60,13 @@ class Mailer } else { $this->Path = $path; } - + $this->Method = $method; - + $this->Reset(); $this->LangPath = $this->_GetLangPath(); } - + /** * Bare line feeds do not play nicely with email. * this strips them @@ -76,7 +78,7 @@ class Mailer $str = str_replace("\r\n", "\n", $str); return str_replace("\r", "\n", $str); } - + /** * This function attempts to locate the language file path for * PHPMailer because it's a whiney-ass bitch about finding it's @@ -88,7 +90,7 @@ class Mailer { $lang_path = ""; $paths = explode(PATH_SEPARATOR, get_include_path()); - + foreach ($paths as $path) { if (file_exists($path . '/language/phpmailer.lang-en.php')) { $lang_path = $path . '/language/'; @@ -97,7 +99,7 @@ class Mailer return $lang_path; } - + /** * Send the message. * If MAILER_RESULT_FAIL is returned, use GetErrors() to @@ -109,10 +111,10 @@ class Mailer function Send($message) { $mailer = new PHPMailer(); - + // this prevents problems with phpmailer not being able to locate the language path $mailer->SetLanguage("en", $this->LangPath); - + $mailer->From = $message->From->Email; $mailer->FromName = $message->From->RealName; if ($message->ReplyTo) { @@ -125,79 +127,79 @@ class Mailer $mailer->Mailer = strtolower($this->Method); $mailer->Host = $this->Path; $mailer->Sendmail = $this->Path; - + // use authentication if necessary if ($this->AuthUsername) { $mailer->SMTPAuth = true; $mailer->Username = $this->AuthUsername; $mailer->Password = $this->AuthPassword; } - + // if custom headers are to be provided, include them in the message foreach ($message->Headers as $header_key => $header_val) { $mailer->AddCustomHeader($header_key . ': ' . $header_val); } - + if ($message->Sender) { $this->_log [] = "Adding Sender " . $message->Sender; - + // phpmailer accepts this but it seems to not work consistently..? // $mailer->Sender = $message->Sender; - + // instead add the dang headers ourselves $mailer->AddCustomHeader("Sender: " . $message->Sender); $mailer->AddCustomHeader("Return-Path: " . $message->Sender); } - + if (! $this->IsValid($mailer->From)) { $this->_errors [] = "Sender '" . $mailer->From . "' is not a valid email address."; return MAILER_RESULT_FAIL; } - + // add the recipients foreach ($message->Recipients as $recipient) { $this->_log [] = "Adding Recipient " . $recipient->RealName . " [" . $recipient->Email . "]"; - + if (! $this->IsValid($recipient->Email)) { $this->_errors [] = "Recipient '" . $recipient->Email . "' is not a valid email address."; return MAILER_RESULT_FAIL; } - + $mailer->AddAddress($recipient->Email, $recipient->RealName); } - + foreach ($message->CCRecipients as $recipient) { $this->_log [] = "Adding CC Recipient " . $recipient->RealName . " [" . $recipient->Email . "]"; - + if (! $this->IsValid($recipient->Email)) { $this->_errors [] = "CC Recipient '" . $recipient->Email . "' is not a valid email address."; return MAILER_RESULT_FAIL; } - + $mailer->AddCC($recipient->Email, $recipient->RealName); } - + foreach ($message->BCCRecipients as $recipient) { $this->_log [] = "Adding BCC Recipient " . $recipient->RealName . " [" . $recipient->Email . "]"; - + if (! $this->IsValid($recipient->Email)) { $this->_errors [] = "BCC Recipient '" . $recipient->Email . "' is not a valid email address."; return MAILER_RESULT_FAIL; } - + $mailer->AddBCC($recipient->Email, $recipient->RealName); } - + $result = MAILER_RESULT_OK; - + $this->_log [] = "Sending message using " . $mailer->Mailer; - + ob_start(); // buffer output because class.phpmailer.php Send() is chatty and writes to stdout - + $fail = ! $mailer->Send(); - + ob_end_clean(); // clear the buffer - + if ($fail || $mailer->ErrorInfo) { $result = MAILER_RESULT_FAIL; $this->_errors [] = trim(str_replace(array ( @@ -208,10 +210,10 @@ class Mailer '' ), $mailer->ErrorInfo)); } - + return $result; } - + /** * returns true if the provided email appears to be valid * @@ -221,7 +223,7 @@ class Mailer { return Recipient::IsEmailInValidFormat($email); } - + /** * Clears log and error */ @@ -230,7 +232,7 @@ class Mailer $this->_errors = array (); $this->_log = array (); } - + /** * Utility method to send a simple text email message * @@ -247,10 +249,10 @@ class Mailer $message->Subject = $subject; $message->Body = $body; $message->Format = $format; - + return $this->Send($message); } - + /** * Returns an array of errors that occured during the last attempt * to send a message @@ -261,7 +263,7 @@ class Mailer { return $this->_errors; } - + /** * Returns a log of the last email transaction in array format * -- 2.11.4.GIT