Also see the API documentation for drupal_mail()
and hook_mail()
.
Here is a typical code snippet of mail sending before the changes:
system_send_email_action($object, $context) {
$variables['%site_name'] = variable_get('site_name', 'Drupal');
$variables = array_merge($variables, array(
'%term_name' => $object->name,
'%term_description' => $object->description,
'%term_id' => $object->tid,
'%vocabulary_name' => $vocabulary->name,
'%vocabulary_description' => $vocabulary->description,
'%vocabulary_id' => $vocabulary->vid,
)
);
$from = variable_get('site_mail', ini_get('sendmail_from'));
$recipient = $context['recipient'];
$variables['%username'] = $account->name;
$subject = strtr($context['subject'], $variables);
$subject = str_replace(array("\r", "\n"), '', $subject);
$message = strtr($context['message'], $variables);
$body = drupal_html_to_text($message);
drupal_mail('action_send_email', $recipient, $subject, $body, $from );
}