function crm_core_activity_send_email_action in CRM Core 7
Send e-mail to participants action.
File
- modules/
crm_core_activity/ crm_core_activity.module, line 897 - Provides an entity for recording a contact's activities.
Code
function crm_core_activity_send_email_action($activity, $context) {
$activity = entity_metadata_wrapper('crm_core_activity', $activity);
foreach ($activity->field_activity_participants as $participant) {
if (module_exists('token')) {
// Token replacement preparations.
$data = array(
token_get_entity_mapping('entity', 'crm_core_contact') => $participant
->value(),
token_get_entity_mapping('entity', 'crm_core_activity') => $activity
->value(),
);
$options = array(
// Remove tokens that could not be found.
'clear' => TRUE,
);
$subject = token_replace($context['subject'], $data, $options);
$message = token_replace($context['message'], $data, $options);
}
else {
$subject = $context['subject'];
$message = $context['message'];
}
$email = $participant->primary_email
->value();
if (!empty($email)) {
$params = array(
'subject' => $subject,
'message' => $message,
);
drupal_mail('crm_core_contact', 'crm-core-activity-send-email-action', $email, language_default(), $params);
}
}
}