I changed email source for sending notifications in this module (great module)
I found it in code where it's set, and i want it to be sent to CCK field set in nodes and not to user who made node and i am tring it like this, changing auto_expire_notify function to load node and then send mail to it, seems its WORKING, so just wanted to share this and ask if this is proper way to do it :-)


function _auto_expire_notify($nid, $mailkey, $subject, $body, $args) {
  if (!empty($subject)) {

//load node and get email field
	$node = node_load($nid);
	$user_email = $node->field_email[0]['email'];			
      
      if ($user_email) {
        $subject = t($subject, $args);
        $body    = t($body, $args);
        $params = array('subject' => $subject, 'body' => $body);
        
        $bcc = trim(variable_get(AUTO_EXPIRE_EMAIL .'bcc', ''));
        
        if ($bcc == '') {
          $sent = drupal_mail('auto_expire', $mailkey, $user_email, language_default(), $params);
        }
        else {
          $params['bcc'] = $bcc;
          $sent = drupal_mail('auto_expire', $mailkey .'_bcc', $user_email, language_default(), $params);
        }

Comments

marcvangend’s picture

Status: Active » Fixed

Thanks for sharing this with the community.

Changing module code is of course a 'hack', but I think you realize that. In general, changing module code is not recommended and you should try to make changes using hooks whenever possible. The hook you would normally use to change the address is hook_mail_alter (http://api.drupal.org/api/function/hook_mail_alter/6), but that is not an option in this case because the node ID is not available there. In other words, for this specific purpose, I think there isn't a better option at the moment.

PS. I'm setting the issue status to fixed because nothing is broken :-)

Marko B’s picture

I know its not recommended but as u say i couldnt get node ID so what else option do i get? Also i realized that life is much easier if u change original code, i would have to lose much time to make it in "proper" way and probably wouldnt even find a way to make it like that. I guess you would have to implement tokens into module and make email configurable so then u could use any email you want. Yeah make it fixed :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.