Title: How do you send a message programmatically?
Last modified: September 1, 2016

---

# How do you send a message programmatically?

 *  Resolved [captainmack90](https://wordpress.org/support/users/captainmack90/)
 * (@captainmack90)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-do-you-send-a-message-programmatically/)
 * Hi,
 * I’m using the 3.3.1 beta:
 * Have anybody tried to send a message programmatically based on e.g. user id? 
   Let’s say I have a function that executes in functions.php, how do I send a message
   through Front End PM to that user (I guess from a system account?). Does a hook/
   filter exist for this purpose?
 * Again, thanks for such an awesome plugin Shamim Hasan.
 * – Chris
 * [https://wordpress.org/plugins/front-end-pm/](https://wordpress.org/plugins/front-end-pm/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Shamim Hasan](https://wordpress.org/support/users/shamim51/)
 * (@shamim51)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-do-you-send-a-message-programmatically/#post-7478635)
 * use `fep_send_message()`
 *  Thread Starter [captainmack90](https://wordpress.org/support/users/captainmack90/)
 * (@captainmack90)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-do-you-send-a-message-programmatically/#post-7478780)
 * How do you use it? As far as I could read from the code, I needed to do the following:
 *     ```
       //Send private message to guest.
         $message['message_to_id'] = $guest_id;
         $message['message_title'] = $current_user->user_firstname . __('  confirmed you', 'text-domain');
         $message['message_content'] = __('You have been confirmed as a guest on ','text-domain') . get_post_meta($event_id, '_job_title', true);
         fep_send_message($message);
       ```
   
 * Are there more requirements than the three fields? When sending messages from
   the system.
 *  Plugin Author [Shamim Hasan](https://wordpress.org/support/users/shamim51/)
 * (@shamim51)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-do-you-send-a-message-programmatically/#post-7478826)
 * If you do not set post_author then sender will be current user
 *  Thread Starter [captainmack90](https://wordpress.org/support/users/captainmack90/)
 * (@captainmack90)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-do-you-send-a-message-programmatically/#post-7478843)
 * How would that look? I’ve looked through the code and came up with the following,
   which does not work:
 *     ```
       //Send private message to guest.
         $message['message_to_id'] = $guest_id;
         $message['post_author'] = 1; //TODO: Change to System user ID
         $message['message_title'] = $full_name . __(' have confirmed you', 'text-domain');
         $message['message_content'] = __('You have been confirmed') . '"' . get_post_meta($event_id, '_job_title', true) . '"';
   
         fep_send_message($message);
       ```
   
 * How can you set the post_author? So the “from user” is not the current user?
 * Btw. the latest commit fixed the unread message count problem!
    Thanks!
 *  Plugin Author [Shamim Hasan](https://wordpress.org/support/users/shamim51/)
 * (@shamim51)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-do-you-send-a-message-programmatically/#post-7478844)
 * second argument support $override as array. Supply any value which you want to
   override.
    try following way
 *     ```
       //Send private message to guest.
         $message['message_to_id'] = $guest_id;
         //$message['post_author'] = 1; //TODO: Change to System user ID
         $message['message_title'] = $full_name . __(' have confirmed you', 'text-domain');
         $message['message_content'] = __('You have been confirmed') . '"' . get_post_meta($event_id, '_job_title', true) . '"';
   
       	$override = array (
       		'post_author' => $author_id
       		);
         fep_send_message($message, $override );
       ```
   
 * Also let me know if you found issue about nicename with dashes.
 *  Thread Starter [captainmack90](https://wordpress.org/support/users/captainmack90/)
 * (@captainmack90)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-do-you-send-a-message-programmatically/#post-7478845)
 * Thank you Shamim! That worked straight away.
    There was no problem regarding 
   dashes, I found that someone had switched on some caching, preventing me from
   seeing any arriving messages.
 * Everything working perfectly as of now – great plugin!
 *  [piyam](https://wordpress.org/support/users/piyam/)
 * (@piyam)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/how-do-you-send-a-message-programmatically/#post-7478901)
 * hi
    i tried frontend pm i want to know is it possible, my requirement is i want
   a system i which user can only send message to admin (TO column is hidden, it
   by default is set to admin) second a user and admin see all previous conversation
   between them in one place

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘How do you send a message programmatically?’ is closed to new replies.

 * ![](https://ps.w.org/front-end-pm/assets/icon-256x256.gif?rev=2309447)
 * [Front End PM](https://wordpress.org/plugins/front-end-pm/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/front-end-pm/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/front-end-pm/)
 * [Active Topics](https://wordpress.org/support/plugin/front-end-pm/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/front-end-pm/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/front-end-pm/reviews/)

 * 7 replies
 * 3 participants
 * Last reply from: [piyam](https://wordpress.org/support/users/piyam/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/how-do-you-send-a-message-programmatically/#post-7478901)
 * Status: resolved