We have MimeMail and Mail System installed (see the settings). In my theme, I have /css/mail.css and /templates/mimemail-message.tpl.php. The emails are not using the template. I am sure I've done something wrong, but cannot figure out what it is. Yes, I have cleared the caches many times.

 

<?php 
/**
 * @file
 * Default theme implementation to format an HTML mail.
 *
 * Copy this file in your default theme folder to create a custom themed mail.
 * Rename it to mimemail-message--[key].tpl.php to override it for a
 * specific mail.
 *
 * Available variables:
 * - $recipient: The recipient of the message
 * - $subject: The message subject
 * - $body: The message body
 * - $css: Internal style sheets
 * - $key: The message identifier
 *
 * @see template_preprocess_mimemail_message()
 */
?>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    &lt;?php if ($css): ?>
    <style type="text/css">
      <!--
      &lt;?php print $css ?>
      -->
    </style>
    &lt;?php endif; ?>
  </head>
  &lt;?php $key .= ' nancy'; ?>
  <body id="mimemail-body" &lt;?php if ($key): print 'class="'. $key .'"'; endif; ?>>

  <header id="header" role="banner">

  <div id="header-container">
    &lt;?php if ($site_name || $site_slogan): ?>
      <hgroup id="name-and-slogan">
        &lt;?php if ($site_name): ?>
          <h1 id="site-name">
            <a href="&lt;?php print $front_page; ?>" title="&lt;?php print t('Home'); ?>" rel="home"><span>&lt;?php print $site_name; ?></span></a>
          </h1>
        &lt;?php endif; ?>

        &lt;?php if ($site_slogan): ?>
          <h2 id="site-slogan">&lt;?php print $site_slogan; ?></h2>
        &lt;?php endif; ?>
      </hgroup><!-- /#name-and-slogan -->
    &lt;?php endif; ?>

  </div>
  <div id="colorbar"></div>
  </header>

    <div id="center">
      <div id="main">
        &lt;?php print $body ?>
      </div>
    </div>
    <div id="nancy"><p>Hi, Nancy.</p></div>
  </body>
</html>
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sgabe’s picture

Title: How to get a template used » Theme to render the emails settings does not apply anymore
Project: Mime Mail » Mail System
Version: 7.x-1.0-beta1 » 7.x-2.34
Component: User interface » Code
Category: support » bug

It seems the theme setting does not apply because the theme_registry does not contain the "mail theme" element for mimemail_message.

Mail System expects the "mail theme" element (set in Mime Mail's hook_theme() implementation) in mailsystem_theme_theme_registry_alter().

// Change the registry for hooks with a 'mail theme' element.
foreach ($theme_registry as $name => $hook) {
if (!empty($hook['mail theme'])) {
}

But the registry cache returned by _theme_process_registry() does not contain this element for mimemail_message after the following call (it is removed by it).

// And then the same thing, but for the theme.
if ($theme_engine) {
   _theme_process_registry($cache, $theme_engine, 'theme_engine', $theme->name, dirname($theme->filename));
}

So the proper template file is not loaded...

I am moving this to Mail System, maybe pillarsdotnet have a clue what is happening here.

sgabe’s picture

#2191629: Template not picked up is marked as a duplicate of this.

atolborg’s picture

Im having the same problem. Mails are always sent using current theme. This is critical.

sgabe’s picture

#2311651: Not using mimemail-message.tpl.php in theme folder has been marked as a duplicate of this.

MariskaTh’s picture

Hello, I've seen a lot of duplicate messages of this, but I didn't find a solution. Is there a solution to this issue?

Best regards,
Mariska.

jwilson3’s picture

Hi, I'm currently backporting the Mail System integration for the Mime Mail module to Drupal 6 for this issue: #1088914: The Mime Mail module should use the Mail System module.

I was having this same problem (the mimemail-message.tpl.php in my front-end theme is not being picked up when using an admin theme to test emails being sent) in the D6 version of Mail System, and figured I'd just shared what I'm doing to get it working, in the hopes that it might point the people having trouble with this on Drupal 7 in the right direction.

The problem for me on D6 boiled down to three things; two issues with MailSystem, and one in MimeMail:

1) Mail System bug #1: _theme_load_registry() doesn't return a registry in Drupal 6, so the following line in MailSystem's hook_registry_alter() function simply doesn't work:

        $cache = _theme_load_registry($theme, $base_theme, $theme_engine);

I replaced that with:

        _theme_load_registry($theme, $base_theme, $theme_engine);
        $cache = theme_get_registry();

2) Mail System bug #2: there is no 'includes' key. In Drupal 6 theme_registry, the key is called 'include files'. (see _theme_process_registry(). In drupal 7 this key was indeed converted to 'includes'. (Note: I've edited this comment after the fact because I didn't find this issue when I initially created this patch, I'll create another patch below that contains a fix for both items #1 and #2.

3) Mime Mail bug: The mimemail_message theme function definition in hook_theme of MimeMail module for D6 did not include the 'mail theme' element (this is part of the patch I'm working on for #1088914).

I'm attaching a patch of part #1 above here to this issue, so that I can use it in conjunction with the second part over on the other issue, to get the integration properly working.

jwilson3’s picture

jwilson3’s picture

I discovered a second Mail System bug: there is no 'includes' key. In Drupal 6 theme_registry, the key is called 'include files'. (See _theme_process_registry().

In Drupal 7 this key was indeed converted to 'includes'.

Note: I've edited my comment #6 above after the fact because I didn't find this issue when I initially created the patch in comment #6. This patch builds on the D6 patch in #6 to add a fix for the 'include files', which is important, if you happen to have a preprocess function in your theme's template file.

NWOM’s picture

#8 is for D6. Is there perhaps a workaround or a fix for D7?

jvogt’s picture

For Drupal 7 with Mime Mail, I'm not positive, but I think what fixed it for my site is under Mail System Settings (admin/config/system/mailsystem) make sure the Theme to render the emails is set to whatever theme contains your custom mimemail-message.tpl.php. Your theme will need a template.php file, though it can be blank.

Other reports of this issue mention a few things that might have something to do with the problem:

  • Child themes
  • Different theme for administration pages
  • Simplenews

I'm not using Simplenews, but the other two do apply to my site.

josh@pixael.com’s picture

Setting the theme in admin/config/system/mailsystem fixed the issue.
Thanks.