[development] HTML emails

Lluís enboig at gmail.com
Wed Jul 16 11:15:19 UTC 2008

A problem with HTML mails and CSS is that they don't render the same
in all mail clients. I have searched a way to convert CSS page into
pure HTML (without CSS) before sending it, but I didn't found any way
to do so. Maybe something like http://wiki.tcl.tk/12383 but for PHP
would make sent mails look better.

On Wed, Jul 16, 2008 at 12:32 PM, Matt Connolly <matt at cabinetuk.com> wrote:
> Yes, I am trying to use "mimemail", just ported the code to Drupal 6
> yesterday.
> The problem is that other modules that don't use mimemail duplicate some of
> its functionality, which makes sense when the module is not present.
> At the moment, I'm manually re-theming the other modules to not create
> "<html><head>" stuff to play nice with mimemail.
> Ideally, though, you could set html head elements in an array in a similar
> fashion to for FORM API so that mimemail (or any HTML aware drupal mail
> module) could interpret and include in the constructed email message in the
> correct place. ie: returning a structured array instead of a flat string.
> Although this may be contrary to how theme functions work...
> It makes sense to me that modules should only create the content that goes
> in a <DIV> tag, just like building a block on the page. However, many
> modules call drupal_add_css or drupal_add_js which ultimately gets added to
> the page when it's rendered. I think email generation should have the same
> ability to include CSS files (which should go in the <HEAD> tag, not a
> <DIV>)
> I notice that mimemail does in fact get the CSS files from drupal and the
> current theme (in the absence of a mail.css file) so you can simply call
> drupal_add_cs() from a theme function that generates email.... just
> confusing if you're generating an email, and then a resulting page at the
> same time.....
> -Matt
> On 16/07/2008, at 10:46 AM, Nathaniel Catchpole wrote:
> There's a patch here that's not had much attention for over a year but would
> provide better support in core: http://drupal.org/node/28604
> You should also look at http://drupal.org/project/mimemail
> Nat
> On Wed, Jul 16, 2008 at 10:22 AM, Omar Abdel-Wahab  wrote:
>> +1
>> I strongly would love to have D7 send HTML e-mails.
>> At least 20 modules will benefit from this step.
>> Omar
>> Matt Connolly wrote:
>>> I haven't looked at drupal 7 yet, so I'm throwing this out there for
>>> discussion.
>>> The D6 mail api seems like it's pretty much designed for plain text
>>> emails, however, a module's implementation of hook_mail can clearly set the
>>> headers of the mail to "Content-Type: text/html; charset=utf-8" and send
>>> rich text.
>>> For example, I'm looking at using "forward" module for the "email this
>>> page" link on a node, and the "simplenews" module, which uses "mimemail" to
>>> send rich emails, including attachments. Both "forward" and "mimemail"
>>> modules create a html header.
>>> The problem occurs when a module implements "drupal_mail_wrapper()" to
>>> build a html header when hook_mail has already done that - you can easily
>>> end up with bodies like:
>>> <!doctype... <-- from drupal_mail_wrapper()
>>> <html>
>>> <head>...</head>
>>> <body><div....
>>> <!doctype. <-- from hook_mail()
>>> <html>
>>> <head> ... etc.
>>> Because there are two opportunities to create the html "head" for the
>>> message: in hook_mail and drupal_mail_wrapper.
>>> I'm throwing this out there for discussion, I think that the hook_mail
>>> should construct the message in a similar fashion to the Form API,
>>> specifying a theme for rendering the body part of the message (ie what goes
>>> in the <body> tag) and anything special that needs to go in the head as
>>> attributes.
>>> That way the message can be constructed only once.
>>> Besides, email clients have been HTML friendly for a *long* time, so I
>>> don't see why Drupal shouldn't have an interface that understands rich email
>>> messages.
>>> Thoughts?
>>> Matt

*La vida és com una moneda, la pots gastar en el que vulguis però
només una vegada.
*La felicitat ha de ser compatible, compartible i cooperativa.
*Envellim quan els records superen les il·lusions.
*Als llocs desconeguts només s'hi arriba per camins desconeguts.
*Abans d'imprimir aquest missatge, pensa en el medi ambient.

More information about the development mailing list