Changeset:
        36556e068f2e
        
https://sourceforge.net/p/mrbs/hg-code/ci/36556e068f2e9f36aa9a0eae5d6d461046e98dd9
Author:
        Campbell Morrison <[email protected]>
Date:
        Wed Sep 23 11:44:40 2015 +0100
Log message:

Improved handling of mail debug output, adding an option to direct output to 
the browser of error_log.

diffstat:

 web/functions_mail.inc     |  64 +++++++++++++++++++++++++--------------------
 web/systemdefaults.inc.php |  12 +++++---
 2 files changed, 42 insertions(+), 34 deletions(-)

diffs (147 lines):

diff -r 2c4593d3bf68 -r 36556e068f2e web/functions_mail.inc
--- a/web/functions_mail.inc    Wed Sep 23 10:49:17 2015 +0100
+++ b/web/functions_mail.inc    Wed Sep 23 11:44:40 2015 +0100
@@ -877,10 +877,7 @@
 {
   global $mail_settings, $enable_periods;
   
-  if ($mail_settings['debug'])
-  {
-    echo "[DEBUG] Preparing email for new or changed booking ... <br>";
-  }
+  mail_debug('Preparing email for new or changed booking ...');
 
   // Add some values to the $data array before we go and create the addresses
   if (!$new_entry)
@@ -893,10 +890,7 @@
   $addresses = create_addresses($data, $action);
   if ($addresses === FALSE)
   {
-    if ($mail_settings['debug'])
-    {
-      echo "[DEBUG] Email abandoned:  no addresses.<br>";
-    }
+    mail_debug('Email abandoned: no addresses.');
     return;
   }
   
@@ -989,7 +983,7 @@
   
   if ($mail_settings['debug'])
   {
-    echo "[DEBUG] Preparing email for deleted booking ... <br>";
+    mail_debug('Preparing email for deleted booking');
   }
   
   // As we are going to cancel this booking we need to increment the iCalendar
@@ -1000,10 +994,7 @@
   $addresses = create_addresses($data, $action);
   if ($addresses === FALSE)
   {
-    if ($mail_settings['debug'])
-    {
-      echo "[DEBUG] Email abandoned:  no addresses.<br>";
-    }
+    mail_debug('Email abandoned: no addresses.');
     return;
   }
   
@@ -1093,6 +1084,30 @@
  * @param string  $charset          character set used in body
  * @return bool                     TRUE or PEAR error object if fails
  */
+
+
+function mail_debug($message)
+{
+  global $mail_settings;
+  
+  if (!$mail_settings['debug'])
+  {
+    return;
+  }
+  
+  $full_message = '[DEBUG] ' . $message;
+  
+  if ($mail_settings['debug_output'] == 'log')
+  {
+    error_log($full_message);
+  }
+  else  // anything else goes to the browser
+  {
+    echo htmlspecialchars($full_message) . "<br>\n";
+  }
+}
+
+
 function sendMail($addresses, $subject, $text_body, $html_body, $attachment, 
$charset = 'us-ascii')
 {
   require_once 'Mail/mimePart.php';
@@ -1114,9 +1129,10 @@
   
   $mail = new PHPMailer;
   
+  mail_debug("Preparing to send email ...");
   if ($mail_settings['debug'])
   {
-    echo "[DEBUG] Preparing to send email ... <br>";
+    $mail->Debugoutput = ($mail_settings['debug_output'] == 'log') ? 
'error_log' : 'html';
     $mail->SMTPDebug = SMTP::DEBUG_CONNECTION; // show connection status, 
client -> server and server -> client messages
   }
   
@@ -1323,27 +1339,17 @@
   
   $mail->set('MIMEBody', $mime['body']);
 
-  // Debug info if required
-  if ($mail_settings['debug'])
-  {
-    echo "[DEBUG] Using backend '" . 
htmlspecialchars($mail_settings['admin_backend']) . "'<br>\n";
-    echo "[DEBUG] Recipients: '" . htmlspecialchars($recipients) . "'<br>\n";
-  }
+  mail_debug("Using backend '" . $mail_settings['admin_backend'] . "'");
+  mail_debug("Recipients: '$recipients'");
   
   if (!$mail->postSend())
   {
-    trigger_error("Error sending email: " . $mail->ErrorInfo, E_USER_WARNING);
-    if ($mail_settings['debug'])
-    {
-      echo "[DEBUG] Failed to send email: " . 
htmlspecialchars($mail->ErrorInfo) . "<br>";
-    }
+    error_log('Error sending email: ' . $mail->ErrorInfo);
+    mail_debug('Failed to send email: ' . $mail->ErrorInfo);
     return false;
   }
 
-  if ($mail_settings['debug'])
-  {
-    echo "[DEBUG] Email sent successfully<br>";
-  }
+  mail_debug('Email sent successfully');
   
   return true;
 }
diff -r 2c4593d3bf68 -r 36556e068f2e web/systemdefaults.inc.php
--- a/web/systemdefaults.inc.php        Wed Sep 23 10:49:17 2015 +0100
+++ b/web/systemdefaults.inc.php        Wed Sep 23 11:44:40 2015 +0100
@@ -1014,12 +1014,14 @@
 // extension '.ics'
 $mail_settings['ics_filename'] = "booking";
 
-// Set this to TRUE if you want MRBS to output debug information to the browser
-// when you are sending email.   If you are not getting emails it can be 
helpful
-// by telling you (a) whether the mail functions are being called in the first 
place
-//(b) whether there are addresses to send email to and (c) the result of the 
mail
-// sending operation.
+// Set this to TRUE if you want MRBS to output debug information when you are 
sending email.
+// If you are not getting emails it can be helpful by telling you (a) whether 
the mail functions
+// are being called in the first place (b) whether there are addresses to send 
email to and (c)
+// the result of the mail sending operation.
 $mail_settings['debug'] = FALSE;
+// Where to send the debug output to.  Can be 'browser' or 'log' (for the 
error_log)
+$mail_settings['debug_output'] = 'browser';
+
 // Set this to TRUE if you do not want any email sent, whatever the rest of 
the settings.
 // This is a global setting that will override anything else.   Useful when 
testing MRBS.
 $mail_settings['disabled'] = FALSE;

------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to