Custom tokens in custom module The story : 
I create lets say a simple module to store input data and sent a mail when you click save. 
Now i done the part of store data, send mail and retrieve data, but i would like to add tokens to the mail part.

So for now i have something like this.

 function mymodule_form (){
         $form['name'] = array(
        '#title' =&gt; t('Your name'),
        '#type' =&gt; 'textfield',
        '#size' =&gt; 60,
        '#maxlength' =&gt; 100,
        '#description' =&gt; t('Input your first and last name.'),

        $form['submit'] = array(
        '#value' =&gt; 'Save',
        '#type' =&gt; 'submit',
        '#submit' =&gt; array('mymodule_submit'),
         );

    return $form;

}


Now you have mymodule_submit that saves the data and sends mail.

function mymodule_submit(){

 here goes the part for saving data into table(not going to write it)....

/*mail send*/
    $text=array();
    $subject=array();
    $mail = db_query("SELECT * FROM {mail_data} WHERE mail_id=2"); 
    foreach ($mail as $data){
        $text = $data -&gt; text;
        $subject = $data -&gt; subject;
    }

    $params = array(
    'subject' =&gt; $subject,
    'body' =&gt; $text,
            );
     $to =$emailto; //db_query that selects from table
     $from =$emailfrom; //db_query that selects from table
    drupal_mail('person', 'my_module', $to, language_default(), $params, $from, $send = TRUE);

    /*end mail send */

}

function mymodule_mail($key,&amp;$message,$params) 
{

  switch ($key) {
    case "my_module":
        $message['subject'] = $params['subject'];
        $message['body'][] = $params['body'];
      break;

  }
 }


Now I made a form for inserting subject and body of mail hence $mail = db_query("SELECT * FROM {mail_data} WHERE mail_id=2");

My question is how can i allow user to use tokens or something else to add tokens like in drupal account mail settings(like: account activation, account blocked etc...), where you can add tokens to text so that you get : 

[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]

So to clarify ... I have a form that user uses to input mail data but for now he can only input text , i want to make it possible for him to use tokens(or something else like drupal_set_message(t('Saved input @var!', array('@var'=&gt;$temp)));) when he inputs data... 

Its a form like mymodule_form.
You would have to add them to a global token piece like [site] for them to be able to be used anywhere tokens are used. 

But to use in a custom module you can use the following hooks:

Generate token info:

/**
 * Implements hook_token_info().
 */
function module_name_token_info() {
  $info = array();
  // Define a new token type.
  $info['types']['my_custom_tokens'] = array(
    'name' =&gt; t('My custom tokens'),
    'description' =&gt; t('A token type for my custom tokens.'),
  );
  // Define any new tokens.
  $info['tokens']['my_custom_tokens']['my_token'] = array(
    'name' =&gt; t('My token'),
    'description' =&gt; t('A token I use in my module.'),
  );
  return $info;
}


Give values to token:

/**
 * Implements hook_tokens().
 */
function module_name_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();

  if ($type == 'my_custom_tokens') {
    // Loop through the available tokens.
    foreach ($tokens as $name =&gt; $original) {
      // Find our custom tokens by name.
      switch ($name) {
        case 'my_token':
          // Work out the value of our token.
          $value = 'Value of token';
          // Give our token it's value!
          $replacements[$original] = $value;
          break;
      }
    }
  }

  return $replacements;
}


That should get you started with custom tokens. I've used this a few different times with different situations and it works very well.