Messaging

Messaging is the module for ExpressioEngine 2 that brings all power of Private Messages, Bulletins (public messages) and Buddies/Blocked lists to frontent templates - even with AJAX support!

Basic concepts

Here are some Basic concepts regaring messaging in ExpressionEngine.

Private Messages are similar to being able to send another user an email. In this case, though, they access the Private Message through the EE website and not with an email program.

You are able to send Private Messages (PM) to one or several site members, add attachments, reply, forward. PMs can be organized in folders.

Unlike Private Messages, Bulletins do not get sent to each sender, but rather are viewable by all members of the member group(s) designated as recipients. Additionally, Bulletins can have an expiration date, making them ideal for mass communication of time-sensitive information. You can think of bulletins as Public messages.

You may organize site members that you communicate with into Buddies List and Blocked List. You may think of Buddies List as list of people you follow (or simply use it for easy access to selected profiles). Blocked List is the list of members from which you will not accept Private Messages.

Bulletins

Compose Bulletin

{exp:messaging:bulletin_compose}
<p>Recipients:
{recipients}
<br /><input type="checkbox" name="recipients[]" value="{recipient_id}" /> {recipient_name}
{/recipients}
</p>
<p>Expire this bulletin on:
<br /><input type="text" name="bulletin_expires" value="{current_time format="%Y-%m-%d %H:%i:%s"}" />
</p>
<p>Message text:
<br /><textarea name="message"></textarea>
</p>
<p><input type="submit" value="send" /></p>
{/exp:messaging:bulletin_compose}

{exp:messaging:bulletin_compose} tag will generate the form used to compose bulletin message.

Form fields:

Form tag parameters:

View Bulletins

{exp:messaging:bulletins}
<div id="bulletin_{message_id}">
Message from <a href="{path=member/profile/{sender_member_id}}">{sender_screen_name}</a> ({message_date format="%Y-%m-%d"}
<hr />
{message}
</div>
{/exp:messaging:bulletins}

{exp:messaging:bulletins} tag will display all or certain bulletin message for logged in user.

Tag parameters (all optional):

Conditional variables:

Single variables:

Private Messages

Compose PM

{exp:messaging:pm_compose save_sent="yes"}
{if warning}
<div class="warning">{warning}</div>
{/if}
<p>Recipient:
<br /><input type="text" name="recipients" value="{recipient_from_url}" />
</p>
<p>Subject:
<br /><input type="text" name="subject" value="{subject}" />
</p>
<p>Message text:
<br /><textarea name="message">{message}</textarea>
</p>
{if attachments_allowed}
<p>Attachments:
<br /><input type="file" name="attachment[]" />
<br /><input type="file" name="attachment[]" />
<br /><input type="file" name="attachment[]" />
</p>
{/if}
<p><input type="submit" value="send" /></p>
{/exp:messaging:pm_compose}

{exp:messaging:pm_compose} is the tag that generates form used for composing the message (and also for replying and forwarding)

In there has been non-critical error after submiting the form (the user has permissions to send the message, but it cannot be delivered for some reason, e.g. recipient is invalid) the error message will not be shown, but the user will be redirected back to message composing page with warning message displayed. Previously entered data will be available in corresponding variables.

Form fields:

Form tag parameters:

Conditional variables:

Single variables:

Variable pairs:

{attachments backspace="X"}{/attachments} — used to display list of attachment for message being forwarded. Can be used to populate forward_attachments[] fields for selecting which attachments should be forwarded too. Inside {attachments} following variables are available:

backspace parameter is optional and lets you remove X last characters from the output.

Example forwaring message:

{exp:messaging:pm_compose forwarding="{segment_3}"}
{if warning}
<div class="warning">{warning}</div>
{/if}
<p>Recipient:
<br /><input type="text" name="recipients" value="" />
</p>
<p>Subject:
<br /><input type="text" name="subject" value="{subject}" />
</p>
<p>Message text:
<br /><textarea name="message">{message}</textarea>
</p>
{if attachments}
<p>Attachments:
{attachments}
<br /><input type="checkbox" value="{attachment_id}" name="forward_attachments[]" /> {attachment_name}
{/attachments}
</p>
{/if}
<p><input type="submit" value="send" /></p>
{/exp:messaging:pm_compose}

Example replying to message:

{exp:messaging:pm_compose replying="{segment_3}"}
{if warning}
<div class="warning">{warning}</div>
{/if}
<p>Recipient:
<br /><input type="text" name="recipients" value="{exp:messaging:author message_id="{segment_3}"}" />
</p>
<p>Subject:
<br /><input type="text" name="subject" value="{subject}" />
</p>
<p>Message text:
<br /><textarea name="message">{message}</textarea>
</p>
<p><input type="submit" value="send" /></p>
{/exp:messaging:pm_compose}

View messages in folder

<p>Messages in {exp:messaging:folders folder_id="{segment_2}"}{folder_name}{/exp:messaging:folders}</p>
<table class="pm">
<tr>
<th></th>
<th>From</th>
<th>Subject</th>
<th>Date</th>
</tr>
{exp:messaging:private_messages folder_id="{segment_2}" paginate="both" limit="20" form="yes"}
{if no_results}
<tr>
<td class="no_results" colspan="4">No messages here</td>
</tr>
{/if}
{paginate}
<tr>
<td class="pager" colspan="4">{pagination_links}</td>
</tr>
{/paginate}
<tr id="pm_{message_id}">
<td>
<input type="checkbox" name="message_id[]" value="{message_id}" />
</td>
<td>
<a href="{path=member/profile/{sender_member_id}}">{sender_screen_name}</a>
</td>
<td>
<a href="{path=messages/view/{message_id}}" class="{if has_attachment}attach {/if}{if replied}reply {/if}{if forwarded}fwd {/if}{if unread}new {/if}">{subject}</a>
</td>
<td>
{message_date format="%Y-%m-%d"}
</td>
</tr>
{if '{count}'=='20' OR '{absolute_count}'=='{total_results}'}
<tr>
<td colspan="4" class="pm-move">
Move selected messages: {folder_select} <input type="submit" name="move" value="move selected" /> <input type="submit" name="delete" value="delete selected" />
</td>
</tr>
{/if}
{/exp:messaging:private_messages}
</table>

{exp:messaging:private_messages} (or {exp:messaging:pm}, which is the same) tag will display private messages for logged in user.

Tag parameters (all optional):

Conditional variables:

Single variables:

Variable pairs:

{attachments backspace="X"}{/attachments} — used to display list of files attached with the message.

{recipients backspace="X"}{/recipients} — used to display list of recipients for this message

{cc backspace="X"}{/cc} — used to display list of copy recipients for this message

backspace parameter is optional and lets you remove X last characters from the output.

View messages list grouped by conversation

{exp:messaging:conversations} tag lets you display list of messages grouped by conversation (sender/recipient pair and subject). Similar to Facebook- or Gmail- style.

{exp:messaging:conversations combined="yes" limit="25" paginate="both"}

{paginate}
{pagination_links}
<ul>
{first_page}
<li><a href="{pagination_url}" class="page-first">First Page</a></li>
{/first_page}

{previous_page}
<li><a href="{pagination_url}" class="page-previous">Previous Page</a></li>
{/previous_page}

{page}
<li><a href="{pagination_url}" class="page-{pagination_page_number} {if current_page}active{/if}">{pagination_page_number}</a></li>
{/page}

{next_page}
<li><a href="{pagination_url}" class="page-next">Next Page</a></li>
{/next_page}

{last_page}
<li><a href="{pagination_url}" class="page-last">Last Page</a></li>
{/last_page}
</ul>
{/pagination_links}
{/paginate}

<p>{conversation_count}. <strong>{subject}</strong> - {last_message_date format="%Y-%m-%d"} - from {last_sender_screen_name} ({last_sender_username}) - to {last_recipient_screen_name} ({last_recipient_username}) ({messages_in_conversation} messages in conversation)

{conversation}
<br />
{count}. #{message_id} sent from {sender_screen_name} ({sender_username}) to {recipient_screen_name} ({recipient_username}) on {message_date format="%Y-%m-%d"}
{/conversation}
</p>

{/exp:messaging:conversations}

Tag parameters:

Single variables:

{conversation backspace="X"}{/conversation} variables pair is used to display individual messages inside conversation.

Inside {conversation} variables pair, following are available:
conditionals:

single variables:

View messages in conversation mode

{exp:messaging:pm_thread} tag lets you display messages as thread or conversation. Is displays complete conversation thread between pair of recipient and sender (identified by subject).

{exp:messaging:pm_thread message_id="{segment_3}" backspace="6"}
{if "{count}"=="1"}<p><strong>{subject}</strong></p>{/if}
<p>From: <a href="{path=member/profile/{sender_member_id}}">{sender_screen_name}</a></p>
<p>To: {recipients backspace="1"}<a href="{path=member/profile/{recipient_member_id}}">{recipient_screen_name}</a>, {/recipients}</p>
<p>Sent on: {message_date format="%Y-%m-%d"}</p>
<div class="message" {if current_message} style="font-weight: bold"{/if}>{message}</div>
<hr />
{/exp:messaging:pm_thread}

Tag parameters:

All variables presented by {exp:messaging:private_messages} are available with this tag as well. Additionally, following conditional can be used:

View PM

To display particular message, you'll need to use same {exp:messaging:private_messages} tag, but with member_id parameter set.

{exp:messaging:private_messages message_id="{segment_3}"}
<p>From: <a href="{path=member/profile/{sender_member_id}}">{sender_screen_name}</a></p>
<p>To: {recipients backspace="1"}<a href="{path=member/profile/{recipient_member_id}}">{recipient_screen_name}</a>, {/recipients}</p>
<p>Sent on: {message_date format="%Y-%m-%d"}</p>
<p><strong>{subject}</strong></p>
<div class="message">{message}</div>
{if has_attachments}
<div class="att">
{attachments}
<a href="{download_url}">{attachment_name}</a> ({attachment_size})<br />
{/attachments}
</div>
{/if}
<p><a href="{path=messages/reply/{message_id}}">Reply</a> - <a href="{path=messages/forward/{message_id}}">Forward</a> - <a href="{delete_url}">Delete</a></p>
{/exp:messaging:private_messages}

Moving and deleting messages

To be able to move message to different folder, call {exp:messaging:private_messages} with form="yes" parameter. Then, you'll have {folder_select} variable containing dropdown select of available folders. ID of messages that should be moved should be in inpus (usually checkboxes) named message_id[]. If the submitted form will contain input named 'delete' the message(s) will be deleted instead (moved to Trash, or deleted permanently if they're in Trash already).

You can also delete message by clicking {delete_url} generated by same tag for each message.

Message author

{exp:messaging:author message_id="{segment_3}"}

{exp:messaging:author} will return sender's screen name for message defined by message_id parameter.

Message recipients

{exp:messaging:recipients message_id="{segment_3}"}

{exp:messaging:recipients} will return comma-separated list of recipient screen names for message defined by message_id parameter.

Message folders list

<ul>
{exp:messaging:folders}
<li><a href="{path=messages/folder/{folder_id}}">{folder_name}</a> ({messages_count})</li>
{/exp:messaging:folders}
</ul>

{exp:messaging:folders} tag is used to display list of user's PM folders (and also for folders editing, see below).

Tag parameters:

Single variables:

Editing folders

{exp:messaging:edit_folders}
{exp:messaging:folders show_new="one"}
<p><input name="folder{folder_id}" value="{folder_name}" /></p>
{/exp:messaging:folders}
<p><input type="submit" value="save" /></p>
{/exp:messaging:edit_folders}

Folders editing is done by combining {exp:messaging:edit_folders} and {exp:messaging:folders} tags

In ExpressionEngine, the users are able to create 8 custom folders (plus built-in Trash, Inbox and Sent). You can also give your own names to Inbox and Sent. In order to delete folder, submit the form with it's name empty. If folder has been deleted, all messages in it will be moved to Trash.

Tag parameters:

Form fields:

Member's general PM info

{exp:messaging:info}
You have {messages_total} stored out of {messages_limit} allowed ({messages_percent}%)
{/exp:messaging:info}

Single variables:

Member lists

Buddies list

<ul>
{exp:messaging:buddies}
<li><a href="{path=member/profile/{member_id}}">{screen_name}</a> ({remove_link})</li>
{/exp:messaging:buddies}
</ul>

{exp:messaging:buddies} will display list of buddies for logged in person.

Tag parameters (all optional):

Single variables:

All single variables are also available with buddy_ prefix (buddy_member_id, buddy_username, etc.) that can be used if you run into variable naming conflicts.

Blocked list

<ul>
{exp:messaging:blocked}
<li><a href="{path=member/profile/{member_id}}">{screen_name}</a> ({remove_link})</li>
{/exp:messaging:blocked}
</ul>

{exp:messaging:blocked} will display list of members blocked/ignored by logged in person.

Tag parameters (all optional):

Single variables:

All single variables are also available with buddy_ prefix (buddy_member_id, buddy_username, etc.) that can be used if you run into variable naming conflicts.

Adding to list

<ul>
{exp:query sql="SELECT * FROM exp_members WHERE group_id=5"}
<li><a href="{path=member/profile/{member_id}}">{screen_name}</a> (<a href="{exp:messaging:add_to_buddies_link url_only="yes" member_id="{member_id}"}">Follow</a>)</li>
{/exp:query}
</ul>

Use {exp:messaging:add_to_buddies_link}tag to display link that would allow to add person to buddies list; {exp:messaging:add_to_blocked_link} - for adding to blocked list.

Tag parameters (all optional):

Removing from list

The links for removing person from buddies/blocked list can be displayed using {remove_link} variable in {exp:messaging:buddies} and {exp:messaging:blocked}

Check buddy/blocked state

<ul>
{exp:messaging:check_buddy_state member_id="{member_id}"}
{if blocked}Blocked - {remove_link}{/if}<br />
{if buddy}Followed - {remove_link}{/if}<br />
{/exp:messaging:check_buddy_state}
</ul>

{exp:messaging:check_buddy_state} allows you to check whether certain user has been added to buddies/blocked list by logged in person.

Tag parameters:

Single variables:

Conditional variables:

Extension hooks

The module contain several extension hooks, that allow triggering of custom extensions upon certain event.

messaging_bulletin_sent

Triggered after bulletin has been sent.

Parameters:
— (string) $bulletin_message - bulletin message text; — (array) $recipients - recipient user groups

messaging_pm_sent

Triggered after PM has been sent, but before email notification goes out.

Parameters:
— (array) $data - message data; — (array) $recipients - recipients; — (array) $cc - carbon copy recipients;

messaging_member_listed

Triggered after user adds someone to buddies/blocked list.

Parameters:
— (int) $member_id - ID of member that performs the action (adds to the list); — (int) $listed_member - ID of member added to the list; — (string) $type - list type (buddy/blocked);

Top of page