Subscribe to this site Follow me on Twitter Friend me on Facebook Find me on Ravelry Follow me on Flickr

Turn Off Backgrounds In Drupal Emails

Comments Off

This  post is probably more for me than 95% of my blog readers, so bear with me here. I had a seemingly small issue with my comments and contact form emails. Every email that Drupal sent to me would have my website background as the background of the email. If you have ever used my contact form, you may have noticed this when you received an auto response from me.

I searched several places on how to turn this option off, but I didn’t seem to find anything. I dug down into the Contact and Comment modules and nothing. Finally I started looking into the Mime Mail module that I use to send the actuall emails. That’s when I noticed a little piece of code that was causing my issues:

functiontheme_mimemail_message($body,$mailkey=null) {
$output='<html><head>';
$output.='<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';

// attempt to include a mail-specific version of the css.
// if you want smaller mail messages, add a mail.css file to your theme
$styles=path_to_theme() .'/mail.css';

As it turns out, the Mime Mail module allows you to create a style sheet called “mail.css” and style your emails. If it doesn’t see that lovely file, it pulls the tags from your main style sheet. In my case it would pull the body tag which looks a little like this:

body { background: url(bodybg.gif) repeat; color:#555; }

I now see that’s why the emails had that background. I could have changed the module to exclude¬† the html output, or the CSS files altogether, but I really hate to hack a module and then when I upgrade I forget about it (and the hack I made), or just break it altogether. My down and dirty fix was to create a file called mail.css in my theme folder. I left the file blank until such a time that I decide I’d like to style my emails.

So there you have it, just a quick little reminder to myself and anyone else who may run across this problem.

Comments are closed.