I'm using htmlmail module. I'm trying to send an email after node save. So I put drupal_mail() into hook_node_insert() or hook_node_presave(), but when I'm doing this, the body of my emailes are empty.
The source looks literally like this:
<div class="htmlmail-body">
</div>
The templates are not processed. The hook_preprocess_htmlmail() function in template.php is not beeing invoked. I'm using different templates for different mail keys.
Now the funny thing is that when I'm using the same drupal_mail() in hook_cron() it just works as expected. I have no idea how I can debug this. Any ideas (for example where to put a debuggers break for further diagnosis)?
Added #1: It appears that only htmlmail.tpl.php is being used instead of my module and key specific templates that works when I'm sending mails from cron.
Added #2: Code in hook_cron() and in hook_node_presave() is the same:
$receipents = array( variable_get('site_mail', '[email protected]') );
$params = array();
drupal_mail('bonds_cron', "create_payments__client", implode(', ', $receipents), language_default(), $params, variable_get('site_mail', '[email protected]'), true);
The difference is that in hook_cron() it works, and in hook_node_presave() it doesn't. I was trying to change double "__" into one, thinking that maybe it's something with picking up templates, but without success. I'm searching now for place in core code, when I could put a break to see what is going on when picking up those templates but I cannot find it. :/
Added #3: template_preprocess_htmlmail() run just fine. The proper template suggestion is added there.
Added #4:
I added var_dump($items)
before the end of htmlmail_theme() function. When clearing cache I got this output:
array(11) {
'htmlmail__bonds-cron__create_payments__admin' =>
array(4) {
'variables' =>
array(1) {
'message' =>
array(0) {
...
}
}
'template' =>
string(44) "htmlmail--bonds-cron--create_payments__admin"
'path' =>
string(35) "sites/default/themes/bond/templates"
'theme path' =>
string(25) "sites/default/themes/bond"
}
'htmlmail__bonds-cron__create_payments__agent' =>
array(4) {
'variables' =>
array(1) {
'message' =>
array(0) {
...
}
}
'template' =>
string(44) "htmlmail--bonds-cron--create_payments__agent"
'path' =>
string(35) "sites/default/themes/bond/templates"
'theme path' =>
string(25) "sites/default/themes/bond"
}
'htmlmail__bonds-cron__create_payments__client' =>
array(4) {
'variables' =>
array(1) {
'message' =>
array(0) {
...
}
}
'template' =>
string(45) "htmlmail--bonds-cron--create_payments__client"
'path' =>
string(35) "sites/default/themes/bond/templates"
'theme path' =>
string(25) "sites/default/themes/bond"
}
'htmlmail__bonds-cron__payments_alert__admin' =>
array(4) {
'variables' =>
array(1) {
'message' =>
array(0) {
...
}
}
'template' =>
string(43) "htmlmail--bonds-cron--payments_alert__admin"
'path' =>
string(35) "sites/default/themes/bond/templates"
'theme path' =>
string(25) "sites/default/themes/bond"
}
'htmlmail__bonds-cron__payments_alert__agent' =>
array(4) {
'variables' =>
array(1) {
'message' =>
array(0) {
...
}
}
'template' =>
string(43) "htmlmail--bonds-cron--payments_alert__agent"
'path' =>
string(35) "sites/default/themes/bond/templates"
'theme path' =>
string(25) "sites/default/themes/bond"
}
'htmlmail__bonds-cron__payments_alert__client' =>
array(4) {
'variables' =>
array(1) {
'message' =>
array(0) {
...
}
}
'template' =>
string(44) "htmlmail--bonds-cron--payments_alert__client"
'path' =>
string(35) "sites/default/themes/bond/templates"
'theme path' =>
string(25) "sites/default/themes/bond"
}
'htmlmail__bonds-cron__tax_alert__admin' =>
array(4) {
'variables' =>
array(1) {
'message' =>
array(0) {
...
}
}
'template' =>
string(38) "htmlmail--bonds-cron--tax_alert__admin"
'path' =>
string(35) "sites/default/themes/bond/templates"
'theme path' =>
string(25) "sites/default/themes/bond"
}
'htmlmail__htmlmail' =>
array(4) {
'variables' =>
array(1) {
'message' =>
array(0) {
...
}
}
'template' =>
string(18) "htmlmail--htmlmail"
'path' =>
string(26) "sites/all/modules/htmlmail"
'theme path' =>
string(25) "sites/default/themes/bond"
}
'htmlmail__simplenews' =>
array(4) {
'variables' =>
array(1) {
'message' =>
array(0) {
...
}
}
'template' =>
string(20) "htmlmail--simplenews"
'path' =>
string(26) "sites/all/modules/htmlmail"
'theme path' =>
string(25) "sites/default/themes/bond"
}
'htmlmail__user__password_reset' =>
array(4) {
'variables' =>
array(1) {
'message' =>
array(0) {
...
}
}
'template' =>
string(30) "htmlmail--user--password_reset"
'path' =>
string(35) "sites/default/themes/bond/templates"
'theme path' =>
string(25) "sites/default/themes/bond"
}
'htmlmail' =>
array(4) {
'variables' =>
array(1) {
'message' =>
array(0) {
...
}
}
'template' =>
string(8) "htmlmail"
'path' =>
string(35) "sites/default/themes/bond/templates"
'theme path' =>
string(25) "sites/default/themes/bond"
}
}
Seems ok for me.