0

I am working with drupal 7 site.

I would like to know how to create email template for any email sent from drupal system?

Is there any hook or template should I implement in my custom module or override to make it beautiful like any newsletter emails are received.

I want following emails should be theming.

  1. User Activation User
  2. Password reset
  3. Comment Notification etc...

Email template should looks like

<header>
Dear <User>
<Message Body goes here>
Thanks
<footer>
1

You can use htmlmail module. which allow you to create template for your email and allow you theme your mail with Echo module. Even you can add your logo, header, footer and any other information with echo module. See detail on these two project's page.

1

Take a look at hook_mail. All emails from the system "should" go through that. You can alter the $message['body'] to add your header and footer. If you only want to do this for certain emails, you can use an IF condition on the $key.

Edit: I think I pointed you to the wrong hook. You probably want to use hook_mail_alter to change every email that Drupal sends.

  • So, I can add override this hook_mail from my module will helpful. e.g. mymodule_mail(){ // to do } – AshwinP Jul 31 '14 at 6:10
  • Yep, that should do it. you can also take a look at the examples module. It has an example of that hook. cgit.drupalcode.org/examples/tree/email_example/… – Craig Jul 31 '14 at 13:18
  • I will try and let you know if there any issue. Thankx – AshwinP Aug 1 '14 at 5:25
  • I updated my original answer... I think you want to use hook_mail_alter to add a header/footer to every email that the system generates. – Craig Aug 1 '14 at 14:35
1

If you are using custom module or willing to do some custom code then please follow this link How to use drupal_mail() to send emails with custom template

I think this is what you are looking for.

  • Let me check that link – AshwinP Aug 4 '14 at 5:18
  • I would like to know that, HOOK_MAIL() hook create using mymodule_mail() always route through my module hook for mail for any mail send from whole system? e.g. commerce module send emails also route from mymodule_mail() to theming body or ONLY System mail can route from mymodule_mail(). – AshwinP Aug 4 '14 at 5:21
  • I didn't get what you asked in the comment but just to let you know, every time a drupal_mail is called every HOOKs associated with hook_mail is invoked. So the mail object gets all the values from all the invoking functions. – Aneek Mukhopadhyay Aug 4 '14 at 6:06
  • Yes, that was I asked. – AshwinP Aug 4 '14 at 6:17

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.