PunBB e-mail notification on each new post extension




On another site I manage, I just switched from the previous forum script to PunBB; one feature I missed after the switch is the ability to activate an email notification for each and every post the users add into the forum, so I had to write my own.
Following is the source code of the extension, save it as manifest.xml, upload it into /extensions/newpost_mail_notify/ PunBB folder (or another name of your liking), and install from PunBB admin panel with the usual method. There is nothing to set, as long as the extension is active it just does its job.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE extension SYSTEM "ext-1.0.dtd">

<extension engine="1.0">
<id>pun_newpost_mail_notify</id>
<title>Send email to admin for each new post</title>
<version>1.1</version>
<description>This extension simply sends an email to the configured admin email address everytime a new post is added by someone who's not the configured admin</description>
<author>Ephestione</author>

<minversion>1.3.2</minversion>
<maxtestedon>1.3.4</maxtestedon>

<hooks>
<hook id="po_pre_redirect"><![CDATA[
if ($forum_user['group_id']!=1) { //default admin user id
$notification_to=$forum_config['o_admin_email'];
$notification_subject='['.$forum_config['o_board_title'].'] New topic/post notification';
$notification_message='New post/thread at URL: '.$base_url.'/viewtopic.php?pid='.$new_pid.'#p'.$new_pid;
mail($notification_to,$notification_subject,$notification_message);
}
]]></hook>

</hooks>

</extension>

This extension is very spartan, it will send a mail to the preconfigured admin email address, only if the new post is by someone else than the admin (obviously), with a simple link pointing to the post in the board.

I just updated the code with the suggestion by Grez from PunBB forums, correcting the check on the user which now uses the group_id and not the user id, thus being more solid.

Disclaimer: not my fault if your server explodes, this extension has been made/tested for PunBB 1.3.4, and if you’re not using that version you should definitely upgrade; may be a bad idea to use it if you get a lot of posts each day; I needed it because my forum is not so active, so I prefer getting notified if there’s something new, rather than go checking everyday.

  This article has been Digiproved




2 thoughts on “PunBB e-mail notification on each new post extension”

    1. Great 🙂 Anyway, as a manner of good practice, you always should leave somewhere on your website a note that says the forum is PunBB, removing the original forum copyright notice and replacing it with your Copyright symbol isn’t going to please the authors!

Leave a Reply

Your email address will not be published. Required fields are marked *