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を手動で呼び出しても処理されないようです()。