diff --git a/changelog.md b/changelog.md
index 117d35cfa..d4622131c 100644
--- a/changelog.md
+++ b/changelog.md
@@ -11,6 +11,8 @@
* Remove unreachable code
* Use older regex validation pattern for troublesome PCRE library versions
* Improve PCRE detection in older PHP versions
+* Handle debug output consistently, and always in UTF-8
+* Allow user-defined debug output method via a callable
## Version 5.2.8 (May 14th 2014)
* Increase timeout to match RFC2821 section 4.5.3.2 and thus not fail greetdelays, fixes #104
diff --git a/class.phpmailer.php b/class.phpmailer.php
index f39d2bfa6..f29a3ff84 100644
--- a/class.phpmailer.php
+++ b/class.phpmailer.php
@@ -310,7 +310,11 @@ class PHPMailer
* 'echo': Output plain-text as-is, appropriate for CLI
* 'html': Output escaped, line breaks converted to
, appropriate for browser output
* 'error_log': Output to error log as configured in php.ini
- * @type string
+ * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
+ *
+ * $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
+ *
+ * @type string|callable
* @see SMTP::$Debugoutput
*/
public $Debugoutput = 'echo';
@@ -628,6 +632,10 @@ protected function edebug($str)
if ($this->SMTPDebug <= 0) {
return;
}
+ if (is_callable($this->Debugoutput)) {
+ call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
+ return;
+ }
switch ($this->Debugoutput) {
case 'error_log':
//Don't output, just log
diff --git a/class.smtp.php b/class.smtp.php
index b96044c2c..3ac43ff35 100644
--- a/class.smtp.php
+++ b/class.smtp.php
@@ -92,7 +92,11 @@ class SMTP
* * `echo` Output plain-text as-is, appropriate for CLI
* * `html` Output escaped, line breaks converted to
, appropriate for browser output
* * `error_log` Output to error log as configured in php.ini
- * @type string
+ * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
+ *
+ * $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
+ *
+ * @type string|callable
*/
public $Debugoutput = 'echo';
@@ -153,6 +157,10 @@ class SMTP
*/
protected function edebug($str)
{
+ if (is_callable($this->Debugoutput)) {
+ call_user_func($this->Debugoutput, $str, $this->do_debug);
+ return;
+ }
switch ($this->Debugoutput) {
case 'error_log':
//Don't output, just log