With the advent of nodes that don't necessarily have a body field, and especially with drupal_render(), I am curious what is now the best approach to send a node's rendered content (albeit converted from HTML to plain text) in an email.

E.g. for a rule triggered on the creation of a new node, how to send that node's content to some address in a "Send Email" action?

Putting this in the action's message field:

<?php
print drupal_render_children(node_view($node));
?>

... results in an email sent out looking like this, missing line breaks between fields:

Field 1: Field 1 ValueField 2: Field 2 ValueField 3: Field 3 ValueField 4: Field 4 ValueField
5: Field 5 ValueField 6: Field 6 Value

Is there a better way to send a node's content in the body of email as part of a "Send Email" action?

Comments

westbywest’s picture

Here is the work-around I was able to find to the missing line-break problem.

<?php
print str_replace('</div>', '</div><br/>', drupal_render_children(node_view($node)));
?>

Seems that the node fields are enclosed in <div> tags. At some point, the core function drupal_html_to_text() is being called on the email body, and this function is not smart enough to insert line breaks in place of each <div></div> pair it strips. The code above just inserts <br/> tags to force drupal_html_to_text() into adding line breaks.

mitchell’s picture

Title: Best approach to including node content in "Send Email" action? » How to: Include node content in "send an email" action
Category: support » task

Please work on solving this, and then create a page in the documentation handbook.

bbruda’s picture

If you got Strint Warning error then change for:

$nodeview = node_view($node);
print str_replace('</div>', '</div><br/>', drupal_render_children($nodeview));
bbruda’s picture

Issue summary: View changes

typo

TR’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)