I sent an email in a function.

My email body is like "Hello [user:name], blablablala -- Team [site:name]".

But the token aren't replace by their values in the email.

What's wrong ?


1 Answer 1


You need to run token_replace on the email body and pass in the user object for the target user. In your function: $global $user;

$emluser = user_load($user->uid);
$body = "Hello [user:name], blablablala -- Team [site:name]";
$body = token_replace($body, array('user' => $emluser));

You don't need to pass anything for the site tokens to be replaced.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.