我正在尝试使用hook_mail_alter挂钩手动向用户发送电子邮件。以下是我的全部功能:
function custom_module_mail_alter(&$message) {
$email = '[user:name],
A site administrator at [site:name] has created an account for you. You may now log in by clicking this link or copying and pasting it to your browser:
[user:one-time-login-url]
This link can only be used once to log in and will lead you to a page where you can set your password.
After setting your password, you will be able to log in at [site:login-url] in the future using:
username: [user:name]
password: Your password
-- [site:name] team';
$account = $message['params']['account'];
$uid = $account->uid;
$_user = user_load($uid);
dpm(token_replace($email, array('user'=>$_user)));
}
输出看起来像这样:
Peter,
A site administrator at Website has created an account for you. You may now log in by clicking this link or copying and pasting it to your browser:
[user:one-time-login-url]
This link can only be used once to log in and will lead you to a page where you can set your password.
After setting your password, you will be able to log in at http://localhost/website/user in the future using:
username: Peter
password: Your password
-- Website team
如您所见,诸如[user:name],[site:name]和[site:login-url]之类的内容已正确处理。唯一未处理的令牌是[user:one-time-login-url]。任何想法为什么会这样?
编辑:仅供参考,令牌确实会在系统自动发送的“欢迎”电子邮件中得到处理,因此令牌模块处于活动状态并且正在工作...当我手动调用token_replace时,似乎并没有得到处理()。
您是否启用了token.module?看起来令牌是在token_token_info()中定义的,而不是在user_token_info()中定义的。
—
2011年
是的,已启用令牌模块,并且我正在使用最新的Beta7 ...这很奇怪。
—
彼得