From 7bd7963cea9ccc8005172f1dd7449f178500c467 Mon Sep 17 00:00:00 2001 From: Diogo Freire Date: Tue, 24 Sep 2013 16:18:31 +1200 Subject: [PATCH 1/3] Tyding up conflicting logic on email alerts HTML2Text was being called on message, but we're sending messages as HTML. This was producing nasty emails and sad alertees. Removed the call to HTML2Text and wrapped functino on text::auto_p() to produce better looking messages --- application/controllers/scheduler/s_alerts.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/application/controllers/scheduler/s_alerts.php b/application/controllers/scheduler/s_alerts.php index 4a2b9c160f..ae9c29bee1 100644 --- a/application/controllers/scheduler/s_alerts.php +++ b/application/controllers/scheduler/s_alerts.php @@ -94,11 +94,11 @@ public function index() $incident_description = $incident->incident_description; $incident_url = url::site().'reports/view/'.$incident->id; $incident_description = html::clean($incident_description); - $html2text = new Html2Text($incident_description); - $incident_description = $html2text->get_text(); + //$html2text = new Html2Text($incident_description); + //$incident_description = $html2text->get_text(); // EMAIL MESSAGE - $email_message = $incident_description."\n\n".$incident_url; + $email_message = $incident_description . "\n\n" . $incident_url; // SMS MESSAGE $sms_message = $incident_description; @@ -179,9 +179,9 @@ public function index() $from[] = $alerts_email; $from[] = $site_name; $subject = "[$site_name] ".$incident->incident_title; - $message = $email_message - ."\n\n".$unsubscribe_message - .$alertee->alert_code."\n"; + $message = text::auto_p($email_message + . "\n\n".$unsubscribe_message + . $alertee->alert_code . "\n"); //if (email::send($to, $from, $subject, $message, FALSE) == 1) if (email::send($to, $from, $subject, $message, TRUE) == 1) // HT: New Code From 294c151aab4e1e87a7b3ac638676bf9480ace915 Mon Sep 17 00:00:00 2001 From: Diogo Freire Date: Wed, 25 Sep 2013 20:42:24 +1200 Subject: [PATCH 2/3] Updating send class to attach a plain text version to message when $html = true --- system/helpers/email.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/system/helpers/email.php b/system/helpers/email.php index 566a0d4729..e67ef8fea5 100755 --- a/system/helpers/email.php +++ b/system/helpers/email.php @@ -113,16 +113,22 @@ public static function connect($config = NULL) * @param boolean send email as HTML * @return integer number of emails sent */ - public static function send($to, $from, $subject, $message, $html = FALSE) + public static function send($to, $from, $subject, $content, $html = FALSE) { // Connect to SwiftMailer (email::$mail === NULL) and email::connect(); // Determine the message type - $html = ($html === TRUE) ? 'text/html' : 'text/plain'; + $header_type = ($html === TRUE) ? 'text/html' : 'text/plain'; // Create the message - $message = new Swift_Message($subject, $message, $html, '8bit', 'utf-8'); + $message = new Swift_Message($subject, $content, $header_type, '8bit', 'utf-8'); + + if ($html === TRUE) + { + $html2text = new Html2Text($content); + $message->attach(new Swift_Message_Part($html2text->get_text(), 'text/plain')); + } if (is_string($to)) { From 634e7916d8f3568d0966177827d95639ef7d4956 Mon Sep 17 00:00:00 2001 From: Diogo Freire Date: Wed, 25 Sep 2013 20:42:54 +1200 Subject: [PATCH 3/3] Cleaning up alerts scheduler --- application/controllers/scheduler/s_alerts.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/application/controllers/scheduler/s_alerts.php b/application/controllers/scheduler/s_alerts.php index ae9c29bee1..385b61e5ce 100644 --- a/application/controllers/scheduler/s_alerts.php +++ b/application/controllers/scheduler/s_alerts.php @@ -86,7 +86,7 @@ public function index() l.latitude, l.longitude FROM ".$this->table_prefix."incident AS i INNER JOIN ".$this->table_prefix."location AS l ON i.location_id = l.id WHERE i.incident_active=1 AND i.incident_alert_status = 1 "); // End of New Code - + foreach ($incidents as $incident) { // ** Pre-Formatting Message ** // @@ -94,8 +94,6 @@ public function index() $incident_description = $incident->incident_description; $incident_url = url::site().'reports/view/'.$incident->id; $incident_description = html::clean($incident_description); - //$html2text = new Html2Text($incident_description); - //$incident_description = $html2text->get_text(); // EMAIL MESSAGE $email_message = $incident_description . "\n\n" . $incident_url;