E-Mail notification "new post"

Submitted by Anonymous on Mon, 05/21/2007 - 12:00
Written by


I searched the board about this topic and found nothing. So I suggest an e-mail notification system if a new post is posted in the forum. I think a configurable notification system would be very nice, e. g. notification only if a new topic is started, general notification, notification only category-specific and so on. I think an e-mail notification would help some people to know, that they are a member of a community...
So if a new member is registered, e-mail notification should be automatically enabled.


Mon, 05/21/2007 - 12:18

The subscription feature already works with email notification.

But not for forums.

Enabling it by default would be a very bad idea, if you are on a forum with several hundred posts per day you will end up with perhaps 1000 e-mail messages in a week per member.


Wed, 05/23/2007 - 18:42


I have a small forum (max = 4 post/week) so I think this function should be enabled by the admin or the user himself. I think, the admin should be able to configure an "automatic enabled/disabled for new member" email notification. If the new member doesn't want this, he/she should be able to disable this feature himself.


I've got the same problem, so i coded a little quick 'n dirty Perl Script which does the job:


use strict;
use DBI;
use Net::SMTP;

#### Konfig
my $dbhost = "localhost";
my $dbname = "forum";
my $dbuser = "your-user-here";
my $dbpassword = "xxxxxxx";

my $mailserver = "mail.example.com";
my $mailfrom = 'forumNotify@example.com';
my $subject = "New Forum Post at example.com";

my $forum_url = "http://www.example.com/forum/";

# Print Debug infos? [0|1]
my $debug = 0;

## Look every X Minutes for new Posts:
my $look_every = 5; # Minutes


my $dsn = "";
my $dbh = "";
my $sth = "";
my $max_time = 0;
my %posts = ();
my %recipients = ();

$dsn = "DBI:mysql:database=$dbname;host=$dbhost";
$dbh = DBI::->connect( $dsn, $dbuser, $dbpassword ) or
die DBI::errstr;

$max_time = time - ($look_every * 60);

$sth = $dbh->prepare(
`usebb_posts`.`id`, `usebb_posts`.`topic_id`, `usebb_posts`.`poster_id`,
`usebb_topics`.`topic_title` , `usebb_members`.`name` ,
FROM `usebb_topics` , `usebb_members` , `usebb_posts`
((`usebb_topics`.`id` = `usebb_posts`.`topic_id`)
AND ( `usebb_members`.`id` = `usebb_posts`.`poster_id`))
AND `usebb_posts`.`post_time` >= $max_time
while( my( $id, $topic_id, $poster_id, $title, $name, $content ) = $sth->fetchrow_array()) {
$posts{$id} = { id => $id,
topic_id => $topic_id,
poster_id => $poster_id,
content => $content,
short_content => substr($content, 0, 60),
title => $title,
name => $name,


if( $debug ) {
print "============\n";
foreach my $key (sort keys %posts) {
print "Key: $key\nTitle: $posts{$key}{'title'}\nPoster: $posts{$key}{'name'}\nCont: $posts{$key}{'short_content'}...\n";
print "============\n\n";

$sth = $dbh->prepare(qq~
SELECT `id` , `name` , `email`
FROM `usebb_members`
WHERE `active` = 1
while( my( $id, $n, $e) = $sth->fetchrow_array() ) {
$recipients{$id} = {
name => $n,
email => $e,

if( $debug ) {
print "============\n";
foreach my $key (sort keys %recipients) {
print "Key: $key Name: $recipients{$key}{'name'} E-Mail: $recipients{$key}{'email'}\n";
print "============\n\n";

if( keys(%posts) > 0 ) {
foreach my $key (sort keys %recipients) {
my $smtp;
$smtp = Net::SMTP->new($mailserver);
$smtp->datasend("From: $mailfrom\n");
$smtp->datasend("To: $recipients{$key}{'email'}\n");
$smtp->datasend("Subject: $subject\n");

foreach my $key (sort keys %posts) {
my $link = $forum_url . "topic.php?post=$key#post$key";
$smtp->datasend("Topic: " . $posts{$key}{'title'} . "\n");
$smtp->datasend("Member: " . $posts{$key}{'name'} . "\n");
$smtp->datasend("Text: " . $posts{$key}{'short_content'} . "..." . "\n");
$smtp->datasend("Link: " . "$link" . "\n");
$smtp->datasend(" \n");
$smtp->datasend(" \n");
$smtp->datasend(" \n");



Adjust the config variables and call the Script by crontab every $look_every minutes.


Chris .... this is EXACTLY what I have been looking for as well. It works perfectly BUT (there is always a but) it does not seem to send email's if the poster does not login.

In my forum, I do not require the poster to login.

Is there a way to pick up these posts ??

thanks so much for this script,


Hi rbur!

To implement your suggestion, i would need a dump of your database,
because mine doesn't allow anonymous posting/reading.

I am not easily able to change that here in my Setup.


Christian, ... thanks for the reply. Just yesterday, I "tweaked" the sql statement and got what I want. It has been under test since yesterday and so far seems to be giving me the desired results (more or less). Couple more days of testing should tell the tale.

FYI.... the following change to your sql query is what I did.


((`usebb_topics`.`id` = `usebb_posts`.`topic_id`)
AND ( `usebb_members`.`id` = `usebb_posts`.`poster_id`))
AND `usebb_posts`.`post_time` >= $max_time


(`usebb_topics`.`id` = `usebb_posts`.`topic_id`)
AND `usebb_posts`.`post_time` >= $max_time

I have commented out the datasend "member" statement because it is giving wrong name on anonymous posts. The posts table has a field called poster_guest which does carry the anonymous name (if they enter one). The poster_id field contains a "0" for the anonymous posters. I will try to place a simple if statement to see if I can get either a login poster or the anonymous poster name to show up in the member datasend statement.

After that... I may try to tweak to send html mail... or by chance have you done that ??

Your code has given me a good start and more importantly ... allowed me to keep using UseBB. I was just starting to research other forum programs that might have this feature when chris0001's post and your VERY timely response came along. Judging from the number of views on this subject, I think many others may also be interested.

Thanks again for your contribution ....