Joomla New Item Email Notification

Dustin  |  Content Management Systems  |  July 6th 2008

This example is for Joomla 1.0.15

If you have worked with Joomla for any length of time you will have noticed that the workflow system has some room for improvement. Following is one way to work around this shortcoming.

When a new item is submitted from the public frontend a Private Message is sent to the Super Administrator. Wouldn’t it be great if we could customize this message and have a copy sent to an email of our choosing? Here is how you do it:

First, edit _ON_NEW_CONTENT in your language file. This is the content of your message. The English language file is located at /language/english.php.

DEFINE('_ON_NEW_CONTENT', "Hello,nA new content item has been submitted by [ %s ] titled [ %s ] for the section [ %s ] and category [ %s ].nPlease go to $mosConfig_live_site/administrator/ to view and approve this article.nPlease do not respond to this message as it is automatically generated and is for information purposes only." );

Second, add the following to the /component/com_content/content.php right around line 2400 right after:

foreach ($users as $user_id) {
$msg = new mosMessage( $database );
$msg->send( $my->id, $user_id, "New Item", sprintf( _ON_NEW_CONTENT, $my->username, $row->title, $section, $category ) );
}

Add:

mosMail( "noreply@yourdomain.com", "Admin", "noreply@yourdomain.com", "New Item", sprintf( _ON_NEW_CONTENT, $my->username, $row->title, $section, $category ) );

Now an email containing the new content information will be sent in addition to the PM. You can set rules where you receive this email to check the section and/or category. Then simply forward the email to the publishers for those content groups. Hopefully the next version of Joomla will have better workflow capabilities built in.

Warning: This is a hack!
I personally hate hacks, but when the client asks for a feature that can’t easily be built into an extension sometimes it is the most efficient option. If you use this just be warned that you will have to re-apply this hack if you ever upgrade.

Disclaimer: This has worked for me, but please use at your own risk!

11 Responses to “Joomla New Item Email Notification”

  1. Justin Cook says:

    Thanks. Do you know if this could work in 1.5?

  2. Dustin says:

    I haven’t tried setting this up in 1.5 as of yet, but I don’t see any reason why you couldn’t do something similar. I wouldn’t be surprised if someone has already found a way to do this without a hack in 1.5.

    If I come across something I’ll post it here.

  3. revive says:

    Great article. Love to hear if Justin was able to incorporate it into J1.5 or if you came across anything. I’m looking for this functionality for J1.5.8 now.
    :)

    Cheers and keep up the great work!

  4. Flushface says:

    Hy all!

    No, with the version J1.5.X it doesn’t work. But you change it too.
    You must change the com_messages.ini in your language folder.
    ——————
    PLEASE LOGIN TO READ YOUR MESSAGE=the website url (%s) public. %s
    ——————

    Important is the “%s” at the end.

    Then you must change the file \administrator\components\com_messages\tables\messages.php
    ————————
    $subject = sprintf (JText::_(‘A new private message has arrived’), $sitename);
    $msg = sprintf (JText::_(‘Please login to read your message’), $siteURL, $message);
    ————————-

    the change of this is the variable $message.

    good luck!

    cheers

  5. search engines says:

    It sounds like you’re creating problems yourself by trying to solve this issue instead of looking at why their is a problem in the first place

  6. Owen says:

    I’m working through the differences with 1.5 right now and so far these are the difference I’ve found to make this hack work :

    The English (BG) language file is now /language/en-GB/en-GB.com_content.ini

    Change the entry here to what you wish.

    Then in /components/com_content/controller.php ~~ line 218 change the foreach loop here to say :

    foreach ($users as $user_id)
    {
    JUtility::sendAdminMail($adminRow->name, $adminRow->email, ”, JText::_(‘New Item’), $post['title'], $user->get(‘username’), JURI::base());
    $msg = new TableMessage($db);
    $msg->send($user->get(‘id’), $user_id, JText::_(‘New Item’), JText::sprintf(‘ON_NEW_CONTENT’, $user->get(‘username’), $post['title'], $section, $category));
    }

  7. Dustin says:

    Cool. Thanks Owen.

  8. Umbobabo says:

    Hi,
    well done:

    Do you think it’s possibile modify this code…
    Then you must change the file \administrator\components\com_messages\tables\messages.php
    ————————
    $subject = sprintf (JText::_(‘A new private message has arrived’), $sitename);
    $msg = sprintf (JText::_(‘Please login to read your message’), $siteURL, $message);

    to insert in the message the direct link to backend-content or the Article title?

    Thanks in advance

  9. JR says:

    I tried this in Joomla 1.5 too, but couldn’t get Owen’s solution to work. So here is what I did (this solution also allows more flexibilty in the message sent):

    -search for “foreach ($users as $user_id)” in /components/com_content/controller.php
    -add the following lines at the top of the loop:
    ### EXTRA LINES ADDED HERE TO SEND EMAIL NOTIFICATION
    # Invoke JMail Class
    $mailer = JFactory::getMailer();

    # Set sender — array so that my name will show up neatly in your inbox
    $mailer->setSender(array(“me@mydomain.com”, “myname”));

    # Set recipient — this can be a single address (string) or an array of addresses
    $mailer->addRecipient(“yourname@yourdomain.com”);

    # Set Subject
    $mailer->setSubject(“New article submitted”);

    # Set Body
    $mailer->setBody(JText::sprintf(‘ON_NEW_CONTENT’, $user->get(‘username’), $post['title'], $section, $category));

    # Send once you have set all of your options
    $mailer->send();

    ### END OF EXTRA LINES

    -no need to change any other files, unless you want to modify what ON_NEW_CONTENT says (or add a new constant), in which case edit “\language\en-GBen-GB.com_content.ini”.

    Regards.

  10. JR says:

    Hi Umbobabo,

    As you seem to be suggesting, an alternative approach in Joomla1.5 is to go to the messaging section in the console, go to settings and select “Mail me on new Message”. Then update \administrator\components\com_messages\tables\messages.php to provide the message content rather than just telling you there is a new message. However, I think this would involve greater changes than the change I suggested above because you would have to alter the number of arguments going into the ‘send’ function in that file and alter how it is called etc, so it seems like too much effort for the same result. However, I’m only a newbie so could have this wrong.
    JR

Leave a Reply

Klovera is a forward thinking, full service digital agency whose purpose is to bring value to our clients businesses through creativity, strategy, metrics, user experience and technology.