I want to add a 'flag link' in an email. I have an event content type, and every time a new event created, the users get an HTML Email. I have a flag that the users can flag this event if they want to attend. I want to embed the flag link in the email, so that the users click the link and redirected to the flag confirmation page.

I've tried that with flag_create_link() in the email-template but it has two problems that makes it unusable in an email. First, I'm getting 'Bad token' error if click the link in the Email. Second, the URL generated is a relative URL, so I had to manually change the URL in browser to test, which got me to the first problem.

Is there any proper way to embed a flag link in an Email? So that, the user can click and directed to the confirmation page of the flagging, or login page if he's not already logged in.


I've changed the link type to 'confirmation form' and that solved the first problem. I'm not getting 'Bad token' error anymore. However, the link path is still relative.

  • Try to append $base_url before flag link url. $base_url.flag_create_link()
    – Cool
    Nov 29, 2013 at 11:00
  • It doesn't work. flag_create_link() returns an html link with a span and a in it. So appending the $base_url in front of the span wouldn't help.
    – Elin Y.
    Nov 29, 2013 at 11:57
  • get the href attribute from the returning html link and append the $base_url with href and re-create the link and add it in email content.
    – Cool
    Nov 29, 2013 at 12:05

2 Answers 2


With the following code I managed to create the flag link to embed in the email body:

global $base_url;
$flag_url = $base_url . base_path() . 'flag/confirm/flag/my_flag/' . $nid;

You can try to strip any tags getting in your way:

strip_tags ( string $str [, string $allowable_tags ] )


Your Answer

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

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