I'm using:

  • Drupal 7.19
  • htmlmail 7.x-2.65
  • smtp auth 7.x-1.0 beta 2
  • mail system 7.x-2.34
  • simplenews 7.x-1.0
  • PHP 5.4
  • APC

This error erratically shows itself. There is no seeming rhyme or reason to it. Our cron runs every 3 minutes and sends out 1000 emails each time. The error shows itself in large quantities, but every one seems to get the body. Here is the exact error:
The Theme('htmlmail', $message) function did not return any text. Please check your template file for errors.

I'm not quite sure what else you might need or how else to troubleshoot this. All of my templates seem to work properly when I turn on debugging, it's grabbing the correct templates and giving me the expected outcomes.

Comments

derekw’s picture

Have the same error message. Error message appears and messages are sent without using the template. If I flush the theme registry cache, error message disappears and messages are sent using the template again.

I think it may be occurring after I run the Drupal module update script.

summit’s picture

Version: 7.x-2.65 » 7.x-2.x-dev

Hi,
I got the same error using a custom htmlmail.tpl.php template.
What could be the problem?

Theme hook htmlmail not found.
The theme('htmlmail', $message) function did not return any text. Please check your template file for errors.

Greetings, Martijn

summit’s picture

Issue summary: View changes

cleaned up formatting a bit.

wadmiraal’s picture

Issue summary: View changes

Derekw is right. It does happen on /update.php. But it's not HTML Mail, but Mail System that's the culprit.

It took me a while to figure this one out, but here's what's happening:

When we run /update.php, Drupal clears all the caches (which is normal). The problem is that the mailsystem module uses a theme registry alter hook to put in some custom theme info. This is necessary if you use a different theme for the emails than the site theme. It needs information about Drupal's file structure for this (drupal_get_path, etc).

Problem is: when in update.php context, the file system information is not available (same as in install context). Modules are not supposed to use module_load_* functions, or drupal_get_path, when being installed/updated. This is normal, and keeps critical install logic encapsulated.

So, when the cache is cleared after update, the theme registry is cleared as well. Mailsystem tries to alter the theme registry, fails because it needs file system information, thinks there is no specific email theme so does not trigger an error, and the emails are sent "blank".

The only fix I see: make it a habit of clearing the Theme registry after each update. There's no clean way to do this in code.

Edit: add some formating.

oligodosh’s picture

Had the same issue when using a different theme to handle the htmlmail templates.

After reading wadmiraal's comment I was able to solve the issue following this procedure:

  • Installed mailsystem-7.x-3.0-alpha1
  • The Mail System update procedure didn't work so I uninstalled both mailsystem and htmlmail to start with a clean installation.
  • Re-installed HTML Mail 7.x-2.65
  • Re-configured the whole thing.
  • Then had an issue with htmlmail when trying to send an e-mail:
    Fatal error: Call to undefined function mailsystem_html_to_text() in D:\drupal-7.23\sites\all\modules\htmlmail\htmlmail.mail.inc on line 62
  • Applied the patch found here: Incompatible with latest MailSystem code

The configuration appears to be stable so far even after all caches have been cleared.

salvis’s picture

Status: Active » Closed (outdated)