When sending mail through and AJAX page, the error output breaks a returned JSON object.

The offending code seems to be in smtp.phpmailer.inc, lines 468 and 501:

      echo t('Invalid address') . ': ' . $address;

Why is it outputting directly, rather than through drupal_set_message() or a similar method?

Comments

moonray’s picture

Pretty much all echoed (printed) statements will cause problems.

fabianx’s picture

Status: Active » Needs work

The solution is to use:


ob_start();
// Run PHP Mailer functions here ...
$errors = ob_get_contents();
ob_end_clean();
if ($errors != '') {
  drupal_set_message($errors, 'error');
}

That way phpmailer does not need to be changed and the module does no longer breaks on AJAX.

Setting to "needs work" as someone should make a patch out of above code snippet.

fabianx’s picture

Title: Error messages break AJAX » Error messages break AJAX / debug is spit out directly

Changing title to reflect that this will be a solution also for:

#1085668: Debug prints outside D7 admin overlay

jtsnow’s picture

Issue summary: View changes
StatusFileSize
new1.67 KB

I am having this problem as well. The README.txt file for this module states:

This module no longer uses the PHPMailer package as an external library, instead
a slimmed down version of the library have been relicensed and integrated with the
smtp module.

It looks like the PHPMailer library has already been patched to use t() for translatable strings, so it would seem that patching the library to log errors correctly shouldn't be a concern.

I've attached a patch that modifies smtp.phpmailer.inc to log errors to watchdog instead of printing them to stdout.

jtsnow’s picture

Status: Needs work » Needs review
mkolar’s picture

Thanks for this, echo was ugly.

fabianx’s picture

Status: Needs review » Reviewed & tested by the community
mkolar’s picture

StatusFileSize
new2.42 KB

Here is patch against latest 7.x-1.x branch with implementation of new logging select field from https://www.drupal.org/node/1937416.

mkolar’s picture

Status: Reviewed & tested by the community » Needs review
fabianx’s picture

Status: Needs review » Reviewed & tested by the community
wundo’s picture

Parent issue: » #1937416: Watchdog logging verbose settings
StatusFileSize
new2.4 KB

Updating the patch to reflect changes in #1937416-18: Watchdog logging verbose settings

wundo’s picture

This will have to wait until someone has reviewed #1937416-18: Watchdog logging verbose settings

fabianx’s picture

Still RTBC, other patch is RTBC, too.

  • wundo committed f10d1ef on 7.x-1.x
    Issue #1292490 by mkolar, jtsnow, wundo, Fabianx: Error messages break...
wundo’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.