Hi
I'm using HtmlMail with Simplenews and Echo. My Newsletter content type has, in addition to title and body fields, Signature, Date, Category and Attachment fields.
When I send the newsletter, no HTMLMail theming is applied to the Date, Category and Attachment themes. They all run together in small font at the bottom of the page (I figured out that this come from the Simplenews footer template). I want them to get HtmlMail theming.
I have included a fields--field_name.tpl file for them in my theme templates folder and cleared my caches, with no effect. The newsletter has the correct theming for these fields when viewd on the website but this does not come through in the email.
Interestingly the Signature field is appearing correctly on both the page and the email. But this field is a node reference field in the content type.
Any ideas on what I should do? AT this point I'm willing to dig into php though I'm not a coder.
emk
Comments
Comment #1
pillarsdotnet CreditAttribution: pillarsdotnet commentedThe mail is not sent by rendering the simplenews newsletter page.
Here is the actual chain of events:
simplenews_send_node()
associates the newsletter node id with a list of recipient subscriber ids, and adds them to thesimplenews_mail_spool
table.simplenews_mail_spool()
retrieves the list, switches to the anonymous user, and initiates sending of each newsletter/recipient combination.simplenews_mail_mail()
loads the node object, adds newsletter context, and callsdrupal_mail()
to send the message.drupal_mail()
callssimplenews_mail()
to apply module-specific formatting.simplenews_mail()
callssimplenews_build_node_mail()
translation_node_get_translations()
attempts to fetch a node in the recipient's preferred language. Otherwise,node_load()
is used._simplenews_headers()
adds Simplenews-specific headers to the message.node_view($node, 'email_plain')
converts the node object to a FAPI render array.simplenews_field
theme key is applied to each field in the render array.theme('simplenews_newsletter_body', ...)
converts the render array to HTML message body text.theme('simplenews_newsletter_footer', ...)
converts the same render array to HTML message footer text.simplenews_html_to_text()
converts the message body from HTML to plaintext.drupal_mail()
callsHTMLMailSystem::format()
to format the message.HTMLMailSystem::formatMailMIME()
uses theMailMIME
class functions to parse the message body into MIME parts, convert referenced images into inline attachments, and extract the text/html message part.theme('htmlmail', $message)
applies thehtmlmail--simplenews.tpl.php
template to add custom theming.mailsystem_html_to_text
creates a plaintext alternative to the templated output.echo_themed_page()
passes the message body, title, and theme as POST arguments todrupal_http_request()
, which loads theurl('echo')
page to wrap the themed, templated message body in a mail-specific themed page.check_markup()
applies it to the themed, templated, wrapped message body. This is where the the Emogrifier module may be used to convert CSS stylesheets to inline style attributes.drupal_mail()
passes the themed, templated, wrapped, and converted message to HTMLMailSystem::mail(), which passes the message recipient, subject, body, and headers to the PHP mail() function to send the message.There are lots of places in there where theme callbacks, templates, and overrides can add extra information, but I assure you that the HTML Mail module is not ignoring any of the information made available to it by Simplenews.
Your confusion probably arises because in step 8 above, the
email_plain
view sent by email differs from thefull
view shown on the webpage.If the extra information you desire to include is available in the loaded node object, your best solution is probably to copy the
htmlmail.tpl.php
andhtmlmail--simplenews.tpl.php
to your mail-specific theme directory, and edit the copiedhtmlmail--simplenews.tpl.php
template to reference the$params['node']
and insert the field information as you see fit.If the extra information you desire is available as a block, simply add it to your mail-specific theme by visiting
admin/structure/blocks
.Other solutions include:
hook_mail_alter()
in a custom module.simplenews_newsletter_body
theme implementation in theTHEMENAME_theme()
function of yourtemplate.php
file.THEMENAME_preprocess_htmlmail()
function in your yourtemplate.php
file.Let me know if you need more information/guidance/suggestions/help.
Comment #2
pillarsdotnet CreditAttribution: pillarsdotnet commentedComment #3
pillarsdotnet CreditAttribution: pillarsdotnet commentedCopied the above to a documentation page and linked from the README in the 7.x-2.61 release.
Comment #4
blasthaus CreditAttribution: blasthaus commentedthis is incredibly helpful, thanks huge for this post!
Comment #6
Maciej Lukianski CreditAttribution: Maciej Lukianski commentedThanks for this great post! It really helped me.
I just wanted to add that the node object sits in $params['context']['node']
Comment #7
fantonI get the node object with $params['simplenews_source']->getNode(); in version 7.x-2.65