Sto cercando di inviare e-mail agli utenti manualmente utilizzando l'hook hook_mail_alter. Quanto segue è la mia funzione nella sua interezza:
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)));
}
L'output è simile al seguente:
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
Come puoi vedere, cose come [user: name], [site: name] e [site: login-url] vengono elaborate correttamente. L'unico token che non viene elaborato è [user: one-time-login-url]. Qualche idea sul perché questo stia accadendo?
EDIT: Solo per riferimento, il token non ottenere elaborati nelle e-mail di benvenuto che viene inviati automaticamente dal sistema, in modo che il modulo di token è attiva e funzionante ... Semplicemente non sembra ottenere trasformati quando chiamo manualmente token_replace ().