I have a working html email using modules: Mail System, HTML Mail, SMTP Authentication Support.

And I want to include some parameters/variables in the html email template file:


some variables include: $base_path etc. from page.tpl.php variables

From what I've read from the Internet, you may use "hooking" and I haven't yet hooked variables so far for my template file.


you can use the yourtheme_preprocess_htmlmail() function for htmlmail email template in put in the template.php file of your current theme. I will give an example.

function yourtheme_preprocess_htmlmail(&$variables) {
    case 'password-reset':
     $variables['var1'] = t('SAMPLE TEXT');
    case 'register-no-approval-required':
     $variables['var1'] = t('SAMPLE TEXT');
   $variables['heading'] = t('Heading text');
   $variables['copyright'] = t('Copyright text.');

In this example. I created some customized variables base on the mailkey and defined some others like heading, copyright

| improve this answer | |
  • i've encounter this hook but it seems to me it didn't work, i can't access variables like heading in the htmlmail template file, here is the output of the $variables object in the email for this bin(haha, disregard the infos): phpbin.net/8bYMvJHO by the way, i used another class: HTMLMailSystem__SmtpMailSystem, would it matter the hook function name? – user1076813 Jun 6 '13 at 5:57
  • For the email template, i think you should copy the htmlmail.tpl.php from htmlmail module. I think The htmlmail--htmlmail.tpl.php just uses for testing HTMLMailSystem – Stone Vo Jun 6 '13 at 7:12
  • i see, thanks for this, i just only tried using send test email and the preprocess hook(mytheme_preprocess_htmlmail) doesn't even called/invoked so variables object isn't manipulated/add, why is this? – user1076813 Jun 6 '13 at 9:23
  • and sorry I can't upvode you now since I just started to create this account, soon... – user1076813 Jun 6 '13 at 9:41
  • I checked already. The preprocess_htmlmail function didn't apply for sending test email. You can test that by go to admin/config/people/accounts, enable Notify new user when account created by admin. and create new account to receive a email. Remember set the HTMLMailSystem__SmtpMailSystem value for the Site-wide default MailSystemInterface class in Mail System – Stone Vo Jun 6 '13 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.