Posted by burker on November 2, 2010 at 6:15pm
4 followers
Jump to:
| Project: | Job Search |
| Version: | 6.x-1.1 |
| Component: | Miscellaneous |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
| Issue tags: |
Issue Summary
Hi,
I've been working with the job module for awhile and have managed to put a simple implementation together. My question is about the automatic email. When an applicant applies for a job I would like an email to be sent to the applicant and the job creator (which happens automatically) and another email address that has been added in a job post cck field.
What is the best way to have the extra email sent?
Thanks
Comments
#1
Would also like to know if this is possible. In my project the administrator will be adding the jobs on behalf of the employers. So they would like to receive the email application (as happens automatically) but it should also go to a specified (CCK field) email address for each job, ideally. This saves them the trouble of forwarding them on.
EDIT: think I have cracked this with the following code. Sends to both the user who posted the job (in my case, always the site admin), and also an email address specified in a 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>"))));
}
#2
This is a slight variation on luke76's code, this will send an email to the admin & the user who applied without using any extra fields (i.e. just using the user's account email address).
I have also modified the email text to read better if either role gets the email, if anyone knows a good way to do separate emails for them please let me know!
<?php
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 = $resume_user->mail;
$from = $resume_user->mail;
$language = user_preferred_language($user);
$to = "$job_user->mail";
drupal_mail('job', 'job_apply', $to, $language, $params, $from);
drupal_mail('job', 'job_apply', $contactEmail, $language, $params, $from);
watchdog('job', t("%name applied for job $job_node->nid.",
array('%name' => theme('placeholder', $resume_user->name . " <$from>"))));
}
function theme_job_mail($job_node, $job_user, $resume_node, $resume_user) {
global $base_url;
$site = variable_get('site_name', 'drupal site');
$subject = t("$site Job application for $job_node->title");
$body = t("Thank you for applying for the following job:\n");
$body .= t("\nJob: @title", array('@title' => $job_node->title));
$body .= t("\nPersonal Details:\n");
$body .= t("\nApplicant name: @name", array('@name' => $resume_user->name));
$body .= t("\nApplicant email: @email", array('@email' => $resume_user->mail));
$body .= t("\nCV: @title", array('@title' => $resume_node->title));
// send link to files, if attached
if (variable_get("job_email_files", 0)) {
$file_links = array();
// first, try to include files from any filefields
if (module_exists('filefield') && $fields = filefield_get_field_list($resume_node->type)) {
foreach ($fields as $field) {
$files = $resume_node->$field['field_name'];
foreach ($files as $file) {
$file_links[] = $base_url . url($file['filepath']);
}
}
}
// next, check for file attachments from the core upload.module
if (is_array($resume_node->files) && count($resume_node->files)) {
foreach ($resume_node->files as $file_obj) {
// if this file is not "listed", skip it
if (empty($file_obj->list)) {
continue;
}
// NOTE: for an HTML email, uncomment the following line and comment out the latter instead
$file_links[] = l($file_obj->description, $base_url . url($file_obj->filepath));
// $file_links[] = $base_url . url($file_obj->filepath);
}
}
if (count($file_links)) {
$body .= t("\n\nDownload CV:\n"). implode($file_links, "/n");
}
}
return(array(
'subject' => $subject,
'body' => $body,
));
}
?>
#3
Could this code work for drupal 5?