There are lots of use cases in which an admin role that uses an specific theme want to send an email to anonymous users that have another theme configured.

This patch adds the possiblity to configure which theme will be used to render the email via preprocess and tpl.php.

Current options are:

  • Current theme: Current behaviour
  • Default theme: All mails will be send with the default theme
  • Domain theme: Theme will vary depending on the domain
  • Specific theme: Set an specific theme of all active themes

I think this a major improvement for this module.

Members fund testing for the Drupal project. Drupal Association Learn more


jherencia’s picture

6.48 KB
jherencia’s picture

Assigned: Unassigned » jherencia
Status: Needs review » Needs work

It does not work properly if the theme registry is already built.

sgabe’s picture

Thank you for your work jherencia, this looks pretty neat! Is this also a fix for the theme selection bug (see #1303306: Administration theme used for Actions Emails and #374222: Template files do not work when using admin theme), or is that the part which needs work?

jherencia’s picture

Status: Needs work » Needs review
7.71 KB

Now it works as expected.

As documented in the patch it "just" works with phptemplate engine, there was no way to get which files a theme engine uses in order to include them in the theme registry, so I had to put theme myself manually.

I think that's a minor problem because almost every Drupal theme uses phptemplate engine, I have never seen one that doesn't so I'm not going to spend more time with that.

jherencia’s picture


It changes all the rendering for theme('mimemail_message'), using the theme configured. I haven't tested with simplenews, but if it uses MimeMailSystem interface it will work perfectly well.

It does exactly what #1303306: Administration theme used for Actions Emails was asking so I'm going to change that issue as a duplicate of this, in order to get more reviewers.

sgabe’s picture

It doesn't seem to work for me. I did some testing (with Rules actions and Simplenews) and the messages are always formatted with the admin theme irrespectively from the Mime Mail theme setting.

jherencia’s picture

@sgabe: I've checked it right now with Rules and it works, could you connect to #drupal IRC?

sgabe’s picture

It works, my bad! Don't forget to clear the cache before testing!

jherencia’s picture

8.54 KB

Ok, I attach the same patch but with some minor comment changes and following coding standards (even a fix of an old line).

For those who want to help testing:

After saving the configuration, theme registry is rebuilt but not all the caches. This means that if you add a tpl.php or a preprocess function to a theme, it is needed to clear all caches before sending the email or it won't use any of them to render the email.

sgabe’s picture

7.52 KB

@jherencia: I am attaching a revised patch of yours. Basically I removed some comments and did some code formatting. Furthermore I moved the whole thing into Otherwise it is the same. I think it is good to go, but let me know what you think.

jherencia’s picture

It looks great to me.

sgabe’s picture

Status: Needs review » Fixed

Committed to D7. The patch has been attributed to you. Thanks!

morf2009’s picture

Status: Fixed » Needs review

This update broke my website i'm currently working on. The error:

Deprecated function: Call-time pass-by-reference has been deprecated in drupal_load() (line 1105 of /media/disk/Workspace/

PHP version 5.3.6

Caused by line 96 in file mimemail.module:

return mimemail_theme_theme_registry_alter(&$theme_registry);

to fix this, please change the code to:

return mimemail_theme_theme_registry_alter($theme_registry);

(remove &, left only $).

I'm sorry i didn't created patch for this, but i simply don't have time.

sgabe’s picture

Status: Needs review » Fixed

Thanks for the feedback. The fix will be in the development snapshot soon.

GiorgosK’s picture

Status: Fixed » Active

I can see the setting on mimemail settings
but I can't get it to work (cleared cache/registry cache)
it always tries to get the current theme and or mimemail theme

miro_dietiker’s picture

jherencia’s picture

Well, I've checked this again and it works good to me.

Could you explain exactly how you've tested this?

jherencia’s picture

Status: Active » Fixed

A week with no response, I'm going to reset the status to fixed.

Feel free to change it again and ping me saying how to find the case where it does not work, or better open a new issue once it has been commited.

jherencia’s picture

For those having problems with the CSS it is using when no you don't want to declare a mail.css, please see this: #1378678: Wrong css attached if executing mail via other theme and the mimemail theme specified does not define mail.css.

jherencia’s picture

Title: Add possibility to configure the theme that will render the email » Revert this patch and use mailsystem instead
Status: Fixed » Postponed
6.8 KB
jherencia’s picture

Some changes now that I made mailsystem_get_mail_theme a public function.

jherencia’s picture

6.74 KB


jherencia’s picture

Status: Postponed » Needs review

Ok, @pillarsdotnet committed the patch to Mail system module so now it's in dev version.

Berdir’s picture

Status: Needs review » Needs work
+++ b/mimemail.install
@@ -102,3 +102,13 @@ function mimemail_update_7000() {
+* Implements hook_update_N().
+* @see mimemail_requirements().
+function mimemail_update_7001() {

The docblock for update hooks should just contain a human readable description of the update as it is displayed in the user interface and in drush.

Also, @see shouldn't have a . at the end and you might want to move it to an inline comment to prevent it from being displayed as well (the logic to extract the text isn't exactly intelligent :))

Looks good otherwise.

jherencia’s picture

Status: Needs work » Needs review
6.71 KB

Ups, you are right :).

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me now.

sgabe’s picture

Title: Revert this patch and use mailsystem instead » Possibility to configure the theme that will render the email
Status: Reviewed & tested by the community » Fixed

Committed, thank you guys!

Status: Fixed » Closed (fixed)

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

esclapes’s picture

Status: Closed (fixed) » Active

This appears as commited, but the commit diff looks more like a revert:

Am I missing something?

sgabe’s picture

Status: Active » Closed (fixed)

This feature is available via the Mail System module.