开发者

Get email from Drupal CCK field and send mail using drupal_mail

Hi I'm using the Jobsearch module to build a recruitment site in Drupal 6. By default it sends applications to the email address of the user who posted the job. My problem is all jobs will be posted by a site admin - I need the applications to be sent to BOTH this admin and an email address specified in a CCK field (it's a CCK Email field to be precise).

Trying to extract the CCK field's value and use it in addition to the job poster's (admin's) email and send using drupal_mail but failing - email not sent to the custom CCK email field.

This is what I have attempted (and permutations of), from the Jobsearch module job.module file:

/**
 * Implementation of hook_mail().
 */
function job_mail($key, &$message, $params) {  
  $result = theme('job_mail', $params['job_node'], $params['job_user'],   $params['resume_node'], $params['resume_user']);  
  $message['subject'] = $result['subject'];  
  $message['body'] = $result['body'];  
}  

function job_send_email($job_nid, $resume_nid) {  
  global $user;  

  $params['job_node']    = $job_node = node_load(array('nid' => $job_nid));  
  $params['job_user']    = $job_user = user_load(array('uid' => $job_node->uid));  
  $params['resume_node'] = $resume_node = node_load(array('nid' => $resume_nid));  
  $params['resume_user'] = $resume_user = user_load(array('uid' => $resume_node->uid));  

  $from = $resume_user->mail;  
  $language = user_preferred_language($user);  


  $contactEmail = node_load($field_contact_email[0][nid]);  

  $to = "$job_user->mail, $contactEmail";     

  drupal_mail('job', 'job_apply', $to, $language, $params, $from);  

  watchdog('job', t("%name applied for job $job_node->nid.",  
    array(开发者_开发技巧'%name' => theme('placeholder', $resume_user->name . " <$from>"))));  
}  

It seems like it should be a simple thing to do, but I'm struggling!


Cracked it I think :) This sends to both the poster/user's email and one specified in my CCK email field.

function job_send_email($job_nid, $resume_nid) {
  global $user;

  $params['job_node']    = $job_node = node_load(array('nid' => $job_nid));  
  $params['job_user']    = $job_user = user_load(array('uid' => $job_node->uid));  
  $params['resume_node'] = $resume_node = node_load(array('nid' => $resume_nid));  
  $params['resume_user'] = $resume_user = user_load(array('uid' => $resume_node->uid));  


  $contactEmail = $job_node->field_contact_email[0]['email'];  

  $from = $resume_user->mail;  
  $language = user_preferred_language($user);  



  $to = "$job_user->mail, $contactEmail";     

  drupal_mail('job', 'job_apply', $to, $language, $params, $from);  

  watchdog('job', t("%name applied for job $job_node->nid.",  
    array('%name' => theme('placeholder', $resume_user->name . " <$from>"))));  
}  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜