0

I am sending a message to some users when a specific function is created. However, the content of the message that I send is always in plain text, meaning that it does not render links. What can I do?

This is the function that I use:

$message="A user has requested to join your group ".$group->title.". You can go to the group's page now to approve or decline their request.";

privatemsg_new_thread(array($user), 'New membership request for '.$group->title, $message);

I would this to work:

$message="A user has requested to join your group ".l($group->title,'group/'.$group->gid).". You can go to the group's page now to approve or decline their request.";

Any suggestions?

3
  • Can this help?
    – Jimmy Ko
    Oct 7, 2016 at 9:48
  • 1
    Hi Jimmy, I am using a private message module function. Your link is to format a regular email. Thanks though. Oct 12, 2016 at 9:36
  • Ah... sorry for mis-reading your question.
    – Jimmy Ko
    Oct 12, 2016 at 9:42

1 Answer 1

0

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->nid) && $entity->type == 'entity_type') {
        $author = user_load($entity->uid); // Load the node author.
        $params = array(
            '!first_name' => $account->field_first_name[LANGUAGE_NONE][0]['value'],
            '!last_name' => $account->field_last_name[LANGUAGE_NONE][0]['value'],
            '!node_type' => drupal_ucfirst(str_replace('_', ' ', $entity->type)),
            '!node_title' => $entity->title,
            '!node_url' => url(drupal_get_path_alias('node/' . $entity->nid), array('absolute' => 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;
}
1
  • Thanks, I have tried it, and it works. But I would prefer to avoid showing the full URL and put a hyperlinked phrase instead. I don't understand how url() displays the link, whereas l() displays the tags in plain text instead of the rendered link! Oct 12, 2016 at 11:11

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.