如何利用drupal的API发送邮件
发布网友
发布时间:2022-05-01 12:51
我来回答
共1个回答
热心网友
时间:2023-10-13 10:08
在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);
}
}
?>
热心网友
时间:2023-10-13 10:08
在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);
}
}
?>