Browse files

Merge pull request #1249 from ditorelo/943

Tiding up conflicting logic on email alerts (Issue #943)
  • Loading branch information...
2 parents 932e03f + 634e791 commit e6e619d035c939e202ba39ba878199a046b7f51f @kamaulynder kamaulynder committed Jan 17, 2014
Showing with 14 additions and 10 deletions.
  1. +5 −7 application/controllers/scheduler/s_alerts.php
  2. +9 −3 system/helpers/email.php
View
12 application/controllers/scheduler/s_alerts.php
@@ -95,19 +95,17 @@ public function index()
$incident_query .= "AND DATE(i.incident_date) >= DATE_SUB( CURDATE(), INTERVAL ".($alert_days-1)." DAY )";
}
// End of New Code
-
+
foreach ($incidents as $incident)
{
// ** Pre-Formatting Message ** //
// Convert HTML to Text
$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;
+ $email_message = $incident_description . "\n\n" . $incident_url;
// SMS MESSAGE
$sms_message = $incident_description;
@@ -192,9 +190,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
View
12 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))
{

0 comments on commit e6e619d

Please sign in to comment.