如何利用drupal的API发送邮件

如题所述

在drupal的模块开发中实现发邮件的功能非常简单,只用到一个钩子函数 hook_mail 和一个接口函数drupal_mail.
使用方法如下:

<?php
function example_mail($key, &$message, $params) {
$language = $message['language'];
$variables = user_mail_tokens($params['account'], $language);
switch($key) {
case 'notice':
$message['subject'] = t('Notification from !site', $variables, $language->language);
$message['body'][] = t("Dear !username\n\nThere is new content available on the site.", $variables, $language->language);
break;
}
}

function example_notify($accounts) {
foreach ($accounts as $account) {
$params['account'] = $account;
// example_mail() will be called based on the first drupal_mail() parameter.
drupal_mail('example', 'notice', $account->mail, user_preferred_language($account), $params);
}
}
?>
温馨提示:答案为网友推荐,仅供参考