Here's another approach. (The code is available in this sandbox.)
nodemail.info
name = Nodemail
description = Sends node e-mails.
core = 7.x
nodemail.install'
<?php
function nodemail_enable() {
$current = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
$addition = array('nodemail' => 'NodemailMailSystem');
variable_set('mail_system', array_merge($current, $addition));
}
function nodemail_disable() {
$mail_system = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
unset($mail_system['nodemail']);
variable_set('mail_system', $mail_system);
}
nodemail.module
<?php
class NodemailMailSystem extends DefaultMailSystem {
public function format(array $message) {
$message['body'] = implode("\n\n", $message['body']);
$message['body'] = drupal_wrap_mail($message['body']);
return $message;
}
}
function nodemail_mail($key, &$message, $params) {
switch ($key) {
case 'node_mail':
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8;';
$message['subject'] = $params['subject'];
$message['body'][] = $params['body'];
break;
}
}
function nodemail_node_insert($node) {
if ($node->type == 'mycontenttype') {
$params['subject'] = 'Node "' . $node->title . '" was created';
$params['body'] = render(node_view($node));
$to = variable_get('site_mail', '');
$from = 'noreply@example.com';
$lang = language_default();
drupal_mail('nodemail', 'node_mail', $to, $lang, $params, $from);
}
}
The install file contents and NodemailMailSystem class are used to allow this module to send html e-mails. The 2 other functions are implementations of hook_mail() and hook_node_insert() that deal with sending the e-mails when a node of mycontenttype
is created. One thing you'll have to note is that Drupal will use the node template file of the theme that is being used for node creation pages (or the core node.tpl.php if the theme doesn't have it) for the node view. You may also want to check out the node_view() and drupal_mail() functions that are used here. This whole thing should work with Drupal 7 core functionality (no contributed modules are needed).