Skip to content

Commit

Permalink
Allow injection of a user-defined debug output method, fixes PHPMaile…
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Aug 11, 2014
1 parent 819b9cb commit 165cd47
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion class.phpmailer.php
Expand Up @@ -310,7 +310,11 @@ class PHPMailer
* 'echo': Output plain-text as-is, appropriate for CLI
* 'html': Output escaped, line breaks converted to <br>, 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:
* <code>
* $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
* </code>
* @type string|callable
* @see SMTP::$Debugoutput
*/
public $Debugoutput = 'echo';
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion class.smtp.php
Expand Up @@ -92,7 +92,11 @@ class SMTP
* * `echo` Output plain-text as-is, appropriate for CLI
* * `html` Output escaped, line breaks converted to <br>, 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:
* <code>
* $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
* </code>
* @type string|callable
*/
public $Debugoutput = 'echo';

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 165cd47

Please sign in to comment.