I'm building a small tracker and need to send mail notifications on specific actions.

Thought-out notifications:

  • Administrator gets a notification email when a new ticket is published
  • Author gets a notification email when the ticket is updated
  • Author gets a confirmation mail when the ticket is published

Each notification email will have different content. I've got one of these three notifications to work, the one where the author gets a notification when a ticket is updated (code below). The other two I can't figure out.

Some background on posting in my tracker. The posting takes place in a front end form. If a user is logged in, his user details is used as the ticket author meta. If the user is not logged in, the name and email will be saved as custom fields.

// Send mail to user when a ticket is updated
function trac_authorEditNotification($post_id) {
   $post = get_post($post_id);
   $author = get_userdata($post->post_author);

   if ($author->ID == '2') {
       $message = "Hej ".get_post_meta($post->ID, 'ticket_poster', true).",\nDin rapport '".$post->post_title."' har just uppdaterats.\n\nDu kan besöka den uppdaterade rapporten på: ".get_permalink( $post->ID )."\n\nMvh\nTeamet";
       wp_mail(get_post_meta($post->ID, 'ticket_poster_mail', true), "[Trac] Rapport uppdaterad (#".$post->ID.")", $message);
   } else {
       $message = "Hej ".$author->display_name.",\nDin rapport '".$post->post_title."' har just uppdaterats.\n\nDu kan besöka den uppdaterade rapporten på: ".get_permalink( $post->ID )."\n\nMvh\nTeamet";
       wp_mail($author->user_email, "[Trac] Rapport uppdaterad (#".$post->ID.")", $message);
add_action('edit_post', 'trac_authorEditNotification');

Basically what I need is something similar to the above code for the other two notifications. I've tried a bunch of action hooks but nothings seems to do the trick. I'm getting no email at all or multiple hooks gets triggered and I'm ending up with to many emails.


  • Just add echo 'WORKS!';exit; in your hooked functions to see if they work on update/edit, etc.
    – kaiser
    Nov 13, 2011 at 16:25

1 Answer 1


Unless for some reason you need this to be hardcoded into your theme or have full control over your own plugin, you could use the existing Peter's Collaboration Emails plugin.

If installing a plugin is not an option, I'd suggest modifying the above or borrowing some of its code, respectively. It can do all the things you require.

As an aside, it's also easily adapted to work with just one or several custom post type(s).

  • Installing a plugin is not an option, but I'll check out the plugin you suggested to see if I can figure it out. Thanks for your tip.
    – EyesX
    Nov 13, 2011 at 13:45

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.