How to insert a link in a private message by code?
This is how I do it: 

function _send_notifications($entity, $recipient) {
    $params = set_params($recipient, $entity);
    $sent = privatemsg_new_thread(array($recipient), $params['message_subject'], trim(token_replace($params['message_body']))); 
}

function set_params($account, $entity) {
    if (isset($entity-&gt;nid) &amp;&amp; $entity-&gt;type == 'entity_type') {
        $author = user_load($entity-&gt;uid); // Load the node author.
        $params = array(
            '!first_name' =&gt; $account-&gt;field_first_name[LANGUAGE_NONE][0]['value'],
            '!last_name' =&gt; $account-&gt;field_last_name[LANGUAGE_NONE][0]['value'],
            '!node_type' =&gt; drupal_ucfirst(str_replace('_', ' ', $entity-&gt;type)),
            '!node_title' =&gt; $entity-&gt;title,
            '!node_url' =&gt; url(drupal_get_path_alias('node/' . $entity-&gt;nid), array('absolute' =&gt; TRUE)),
        );
        $data['message_subject'] = t('New node type has been created');
        $data['message_body'] = t(
            "Dear !first_name !last_name,\na new !node_type has been posted with the title \"!node_title\".\n\nYou can view the post here:\n!node_url\n\n--  [site:name] team", $params
        );

    return $data;
}