May 132010

Kunena is a common freely available add-on for the Joomla content management system that gives you the ability to add a message board or forum to your joomla website, with moderation, threads, document uploads, and many other features. The only main feature that seems to be missing is the ability to send all users a regular digest of postings made over a certain period of time. Daily digest functionality exists in other forum software, like Yahoo! Groups and others, and a number of people on the Kunena message boards have talked about wanting such a feature.

I recently helped a local user group migrate from a Yahoo! Groups page to their own website running Joomla for content management and Kunena for forum functionality. They really like the daily digest option Yahoo! offered, so I figured out a way to implement that in the Kunena forum software.

Disclaimer: I’m not a Joomla developer, and this solution has really nothing to do with Joomla. I’m a Linux systems administrator, so my preferred method of approaching this problem was to write a script that would query the database directly, finding the posts made in the last 24 hours, putting them in an html page, and then emailing that page to all the registered users. So this solution is not as simple as ‘install this joomla module’, or ‘check this configuration option’. But it does work very well.

First, I wanted to give the users the ability to opt-out of the email if they wished. Rather than modify one of the existing joomla tables to store this opt-out option, I created a new mysql table:

mysql> describe digest;

| Field         | Type         | Null | Key | Default | Extra |
| username      | varchar(100) | NO   | PRI | NULL    |       |
| receivedigest | char(5)      | NO   |     | NULL    |       |
2 rows in set (0.25 sec)

Here is the sql used to create this table:

CREATE TABLE `digest` (
`username` varchar(100) NOT NULL,
`receivedigest` char(5) NOT NULL,
PRIMARY KEY  (`username`)

The thinking behind this is that everyone is going to get the digest by default. If they choose to opt-out, I will put their username in this table with a value of ‘no’ for the receivedigest field. If they change their mind and want it again, I can either erase them from the table, or change the value to ‘yes’.

Now, you need to create the page that people will use to manage their preferences. I created a directory called “custom” underneath the main directory of my Joomla install to store custom php scripts that are called within Joomla. Here is the first, digest.php:

global $my;
$username = "$my->username";

### / Initial mysql connection
mysql_connect($dbserver,$dbusername,$password) or die (" Can't connect");
@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT * FROM $dbtable where username = '$username';";
while ($i < $query_num)

if ( $result == "yes" )

print "Hello $username!<br><br>";

<form name="digest" id="digest" action="custom/digest_submit.php" method="POST">
<input type="hidden" name="username" value="<?php print "$username" ?>">
<input <? echo "$checked"; ?> name="receive_digest" TYPE="CHECKBOX" VALUE="yes">Check this to receive the daily digest via email<br>
<br><input type="submit" value="Submit"/>


Once the user has made their decision, they submit the form which submits to this page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en" xml:lang="en">
<META HTTP-EQUIV=Refresh CONTENT="3; URL=http://website">

mysql_connect($dbserver,$dbusername,$password) or die ("Sorry! I couldn't connect to the database! Please try again later");
@mysql_select_db($database) or die( "Unable to select database");

# User submitted variables
$insert_date=date("Y-m-d H:i:s");

$username= mysql_real_escape_string($_POST["username"]);
$receive_digest= mysql_real_escape_string($_POST["receive_digest"]);
if ( $receive_digest == "" )
 $receive_digest = "no";

$insert = "REPLACE INTO $dbtable ( username, receivedigest ) VALUES ( '$username','$receive_digest')";

print "<h2>Preferences Updated.</h2>";

Now that you have a preference page, it’s time to actually write the program that find the daily posts and sends the email. Here it is:

rm -Rf ${TMPDIR}
mkdir -p ${TMPDIR}
today=`date --date "yesterday" +%Y-%m-%d`

echo "<html>
<h2>Message Board Digest for ${today}</h2>
You are receiving this email because you are subscribed to the daily digest of the message board. To change your subscription, log into <a href=\"http://website\">website</a> and click \"Daily Digest Options\" from the User Menu.
<table border=1>
Message Date
Posted By
" > ${outfile}

echo "select a.catid,a.thread,from_unixtime(a.time),,a.subject,b.message from jos_fb_messages a,jos_fb_messages_text b where = b.mesid;" | ${mysql_line} | tr "\t" "|" | sed s/"\\\t"/"\&nbsp;"/g | sed s/"\\\n"/"<br>"/g | while read line;
 catid=`echo ${line} | cut -d"|" -f1`
 msgid=`echo ${line} | cut -d"|" -f2`
 msgdate=`echo ${line} | cut -d"|" -f3`
 user=`echo ${line} | cut -d"|" -f4`
 subject=$(echo ${line} | cut -d"|" -f5 |  sed -r s/"\\\\"/""/g)
 message=$(echo ${line} | cut -d"|" -f6 |\
 sed -r s/"url\]"/"url]\n"/g |\
 sed -r s/"\[\/url\]"/"<\/a>"/g |\
 sed -r s/"\[url=(.+)\]"/"<a href=\"\\1\">"/g |\
 sed -r s/"img\]"/"img]\n"/g |\
 sed -r s/"\[\/img\]"/"\">"/g |\
 sed -r s/"\[img\]"/"<img src=\""/g |\
 sed -r s/"\[b\]"/"<b>"/g |\
 sed -r s/"\[\/b\]"/"<\/b>"/g |\
 sed -r s/"\\\\"/""/g)
 if [[ "${msgdate}" =~ ${today}.+ ]]; then
  echo "<tr><td>${msgdate}</td><td>${user}</td><td><a href=\"#${msgid}\">${subject}</a></td></tr>" >> ${outfile}
  echo "<hr><a name=\"${msgid}\">${msgdate} from ${user}</a><br><b><a href=\"http://website/message-board/${catid}/${msgid}\">${subject}</a></b><br>${message}<br><br>" >> ${outfile2}

echo "<hr>" >> ${outfile2}
echo "</table><br>" >> ${outfile}
cat ${outfile2} >> ${outfile}
echo "</body></html>" >> ${outfile}

# figure out who to send the digest to
# for some reason, I stored the table that indicates whether or not a user wants to get the digest in a
# different database than the joomla site was stored in. The first database is "DB1", the joomla database is "DB2"
# modify accordingly for your setup
echo "select  from DB2.jos_users LEFT JOIN DB1.digest on DB2.jos_users.username = DB1.digest.username where (DB1.digest.receivedigest <> 'no' or DB1.digest.receivedigest IS NULL) and DB2.jos_users.username <> 'admin';" | ${mysql_line} > ${TMPDIR}/list_to_email

for item in `cat ${TMPDIR}/list_to_email`
 # append SMTP header
 # replace SENDTO with the appropriate To:
 echo "HELO
 MAIL FROM: admin@website
 From: Daily Digest <admin@website>
 Subject: Daily Digest for $today
 MIME-Version: 1.0
 Content-Type: text/html; charset=us-ascii
 Content-Transfer-Encoding: 7bit" | sed "s/SENDTO/${item}/g" > ${email_file}
 # need an extra newline to conform to HTTP protocol
 # this separates the header from the content
 echo "" >> ${email_file}
 cat ${outfile} >> ${email_file}
 # Tell the mail server we are done
 echo ".
quit" >> ${email_file}
 echo "sending to ${item}"
 cat ${email_file} | /usr/bin/nc localhost 25 1> /dev/null
 sleep 1
rm -Rf ${TMPDIR}

This script gets every Joomla user (except those who have opted out) and emails them the html file created for the last day of messages. I run this out a user’s cron sometime after midnight (since it’s querying for yesterday). And it works and everyone is happy!
Still todo:

  • Handle the formatting in the body of the ‘psuedo-html’ that kunena uses (BBCode)
  • Make the opt-out form more AJAX-y
  • More direct links from the digest into individual threads and users

I know this isn’t the easiest thing to implement, but if you’re not that familiar with Linux, find someone who can help you set this up. Until Kunena comes out with a quicker way to do this, this is probably your best bet.

  49 Responses to “How to add a daily digest email to Kunena forums (Joomla)”


    Hi Adam!

    Thanks for the helpful code. Sure wish the folks at Kunena would implement this important project.

    I'm not a Linux person, and I was able to follow your setup instructions except for the programmatic portion. What type of file is this and where would I put it? Your assistance would be greatly appreciated.

    Neighborhood Wanna B Geek


      Hi JM
      Do you mean the script that starts with "#!/bin/bash" ? That's called a bash shell script, and it's just a text file. If you want to edit it on linux, log in to your linux box and run these commands:

      $ cd /home/username
      $ nano
      Paste the code from my post here and save the file, taking you back to a prompt
      $ chmod +x

      You should now have a file on your system called /home/username/ that has the executable bit set (that's what the 'chmod' command did). In my example, I'm using the editor 'nano' to edit the file. There are many, many other linux editors. If you don't have nano, you can try "pico" or "joe". "vi" will surely be there, but it has quite the learning curve, and that's out of the scope of this article.

      Once you have the file in place, you need to tell your system to run it at a scheduled time. This is usually handled by the 'cron' facility. You tell cron what to run when by editing your user's 'crontab' file. Run the command 'crontab -e' to open up your user's crontab file in your default editor. Then enter a line like this:

      15 0 * * * /home/user/

      This tells cron to run the script at 00:15 everyday (15 minutes after midnight). Change the values to whatever you want.

      Hope this helps


    Oh my goodness! Incredible article dude! Thanks, However
    I am experiencing difficulties with your RSS. I don't
    understand the reason why I cannot subscribe to it.
    Is there anybody getting identical RSS problems? Anyone who
    knows the solution will you kindly respond?



    It's amazing to visit this web page and reading the views of
    all friends concerning this paragraph, while
    I am also keen of getting experience.

    Also visit my website :: Psn Code Generator Online


    Hiya very cool website!! Guy .. Beautiful .. Amazing ..
    I'll bookmark your web site and take the feeds
    also? I'm satisfied to find a lot of useful info right here in the publish, we need work out extra strategies
    in this regard, thank you for sharing. . . . . .


    2 TCO Glass (Thin Film Solar Module Substrate Glass) 6.
    I am always striving to bring a friendly andd professionalattitude combined with very high standard to the fielld of film &video production. ils sont gralement nanmoins sincre personnalis
    polos fait, mais un cot trs nettement rduit.


    Brown and his wife have two daughters, Ayla and Arianna.
    3 liter V8 was only backed by a 4-speed automatic transmission, limiting its efficiency
    and lagging behind when the Sierra and Silverado were fitted with 6-speed
    trans, increasing their MPGs. They organize sales and exhibitions from time to
    time in order to provide benefit to all car lovers.


    Success begets success, to more than a small degree.
    It is people who complicate it more than it really is.
    That is where trading becomes a boring process but eventually it brings very
    good profits. This is the best choice in binary options trading system as shorter the time lesser the fluctuation. You will have underlying asset options and the
    current price of your asset will be listed on the screen. Along
    these lines, Gotoption has officially settled that the brokers that offer the best administrations for US binary options trading are those that are
    spotted in different nations, ideally in Europe.


    Generally I do not learn article on blogs, but I would like to say that this write-up very pressured me to check out and
    do so! Your writing style has been surprised me. Thank you, very nice post.


    This might be the time when the industry is going to have
    to react as there could be a domino effect in how and what is allowed through regulation. And finally its always advisable to
    read and know about the investment system prior making any investments.

    While the concept of binary options is simple, executing a successful strategy is a bit more demanding, though the mechanics of
    purchasing a binary option are not. Binary options trading is
    highly profitable, but you should always do your background research whenever starting out these kinds of investments.

    24option's mission is to introduce you to binary trading.

    Look at how the binary betting strategy
    operates practically.


    You should be a part of a contest for one of the greatest blogs
    online. I most certainly will highly recommend this web


    99% of these websites are offering out dated and old software written in Java.
    It's not a secret that purchasing share in the stock market is really
    a risky business. The reason behind having multiple email accounts is based on the fact
    that if your single email account is taken then the individual who has that account can have
    all your passwords send to that account for

    Take a look at my web site ... trucchi social empires;


    You will rise in the rankings since you're beating another player.
    You are able to furthermore commonly determine if a "line" one other person uses may be practiced or not.
    Further reports say she is not the only victim, but no other names have
    been released.


    If you arre goiing to be late because of traffic call ahead and let them know.
    In thhe winter a closed toe shoe or conservative boot. Now that we have looked at two rules that should be considered unbreakable, let's tackle some options that the business casual man does
    have. Mid-length and fulll length skirts, mosdt often with a
    cenmtre vent to allo for easy movement.


    Excellent way of describing, and pleasant paragraph to take data
    regarding my presentation focus, which i am going to present in college.


    They assure you of unparalleled service, luxury, and convenience in a choice of the best aircraft.
    Also, buying this product can make you learn how to assemble the helicopter
    model since it will be sent to the customer on a kit form.

    Although the use of remote control helicopters is without
    a doubt, a lot, it is not without flaws.


    Now a days affiliate marketing can be a vary lucrative and money making online business only if you have the patience
    to go with it. Today, lots of websites and blogs
    bring in unheard of income for their owners merely by promoting another's company on their web pages.
    A coaching program will help you get started with affiliate marketing and this
    can be the best way to break into the business.

    Make a You - Tube video and make rapturous comments on how
    absolutely fabulous what you are promoting is. If you are paying for a service you will want to check
    out this business before you pay for anything. Sign up with
    those sites that are offering these free services and start posting ads about your product
    by driving targeted traffic to your website.


    What's up friends, good piece of writing and pleasant arguments commented here, I am genuinely enjoying by these.


    Why wait? Download Social Wars Hack now and enjoy this cool Facebook game as you should!

    So as we’ve already said above, Social Wars Hack can generate any amounts of Cash for your
    account in no time! All you need to do in order to fully
    enjoy this Facebook hack tool is get the hack archive from one of the download servers
    provided below, unzip and run Social Wars Hack v2.40.exe.

    Attention! Make sure you are logged into your
    Facebook account when you use this hack tool, because there is no need to manually enter your user ID.

    Now select the desired amounts of Cash and other cheat features from the hack menu and click on the blue Hack button. Wait
    for about five minutes then check your in-game ballance.
    Stunning right? Social Wars Hack is the best hack tool

    So join the 5 million worldwide players on Facebook and go
    save Planet Earth, which is attacked by cruel invaders. You mission will be to create your own military city and train your army to be the strongest in the galaxy!
    Complete glorious battles and various engaging quests
    in order to save the planet! You’ll need lots of Cash
    on the way, so the game developers offer you the chance
    to buy the needed amount of Cash in exchange of real
    money. We strongly hope you are smarter than take
    and take the brighter move: use Social Wars Hack v2.40 for free !

    Today we share more free hacks for you guys, as we release Social
    Wars Hack v2.40 for the greatest action game on Facebook!
    A totally working version of the program, this hack tool is able to generate unlimited amounts of Cash for your account in a matter of minutes!
    So do you need some extra Cash for your Social Wars account?

    Then Social Wars Hack is what you need!

    More great news are about to reveal! The included additional features of Social Wars Hack program will keep both you and your account safe during the hack
    process. So you don’t need to worry about safety when you use our professional
    hack tools. Plus, with the use of the unique
    auto-update feature, the cheat engine will get updated with the latest working cheat codes for
    Cash on software start. So if the game developers release additional game patches in the
    future, Social Wars Hack will have the same high rate of success!

    Social Wars Hack 2014
    How can I safely use Social Wars Hack Tool?


    Thanks for a marvelous posting! I definitely enjoyed reading it, you might be a great author.I will make sure
    to bookmark your blog and will come back in the foreseeable future.
    I want to encourage yourself to continue your great work, have a nice evening!

    My blog: tanah abang


    An impressive share! I have just forwarded this onto a friend who was doing a little research on this.
    And he actually ordered me lunch simply because I found it
    for him... lol. So let me reword this.... Thank YOU for the meal!!
    But yeah, thanks for spending the time to discuss
    this issue here on your web page.


    What a stuff of un-ambiguity and preserveness of precious familiarity about unpredicted emotions.


    One of the latest cars on the market, the Buick Encore is named rightly considering the appreciation that it has been receiving from potential buyers.

    We did like the fact that it offers a choice of any or all vent openings rather than the preselected combinations found in most vehicle heaters.
    Encore trim levels progressively add standard equipment with packages available in both front-wheel and all-wheel-drive models:


    1 fellow was affected by tinnitus after a bullet struck this man
    in the helmet during the latest situations with the terrorist state and
    now he could be fully cured from buzzing in the ears after
    many years of being struck with tinnitus. Likewise, because too much ear wax can head
    to the condition, it may help to simply remove the wax.

    Article Source: searching for a tinnitus cure that works.


    The books have made a remarkable climb in popularity over
    the past few years. The man toured with his father Adrian, who got the same phenomenon with him and performed in French circuses.
    As you drive through Gibtown now, it looks ' almost '
    like any other small Florida town, down to the grocery store,
    the gas station, library, and the odd tattoo parlor.


    It's fantastic that you are getting thoughts
    from this article as well as from our argument made at this


    A car dealer license is usually needed bbut the documents needed tto obtain it wil differ from state to state (country
    too country). However, that is repeatedly not the
    case witth junk cars for sale. It implies that even when they disintegrate, they
    may not degrade fully and instead ppollute the soil.

    My blog - we buy junk cars albany ny


    At this moment I am going away to do my breakfast, later than having
    my breakfast coming yet again to read more news.


    Hi every one, here every person is sharing these knowledge, thus it's nice to read this weblog, and I used to go to see this web site every day.


    With new and Features Clumsy Ninja chat hack
    tool is available to download free of cost.

    Feel free to visit my homepage: clumsy ninja mod apk
    1.6.2 -,


    I do agree with all of the ideas you have introduced
    in your post. They are really convincing and will definitely work.
    Still, the posts are very quick for starters. May you please prolong them a little from subsequent time?
    Thanks for the post.


    Magnificent beat ! I would like to apprentice
    while you amend your website, how can i subscribe for a weblog website?
    The account aided me a applicable deal. I were a little bit acquainted of
    this your broadcast provided shiny clear idea


    Fantastic beat ! I wish to apprentice whilst you amend your site, how could i subscribe
    for a weblog site? The account aided me a acceptable deal.
    I had been a little bit familiar of this your broadcast offered bright clear concept


    It's an awesome paragraph designed for all the online people; they will take
    advantage from it I am sure.


    Novices begin with a virtual bankroll giant sufficient
    to pattern the whole lot, and the variety of casino
    video games offered is notable.


    Hurrah! At last I got a webpage from where I be able to truly obtain useful information regarding my study and


    That is a great tip particularly to those fresh to the blogosphere.
    Short but very accurate info… Many thanks for sharing this one.
    A must read article!


    Quite excellent submit. I came across your site and desired to declare that I've genuinely appreciated surfing around your site content Agen Bola, Bandar Bola, Casino Online, Agen SBOBET, Agen Bola Terpercaya, Bandar Bola Terpercaya, Agen IBCBET, Judi Bola, Agen Bola Terbaik, Bandar Bola Terbaik, Judi Bola Online, Agen SBOBET Terpercaya. Whatever the case I shall be registering to a person's rss with this particular hoping you are writing once again quickly!


    Thank you a lot for sharing this with all folks you actually know what you are speaking about!
    Bookmarked. Kindly also talk over with my site =).

    We may have a link alternate contract among us


    Learners start with a digital bankroll massive enough to sample every little
    factor, and the variety of casino games supplied is notable.


    hello!,I love your writing very so much! percentage we communicate more approximately your article on AOL?
    I need a specialist in this house to unravel my problem.
    May be that's you! Taking a look forward to look you.


    Magnificent beat ! I would like to apprentice while you amend your site,
    how could i subscribe for a blog web site? The account helped me a acceptable deal.

    I had been a little bit acquainted of this your broadcast provided bright clear idea


    I do believe all of the ideas you've introduced
    in your post. They're very convincing and will definitely work.
    Still, the posts are too short for newbies. May just you please prolong them a little from next time?

    Thank you for the post.


    Whilst you dash through the jungle youll be able
    to outrun your folks!


    I'm amazed, I must say. Rarely do I come across a blog
    that's both equally educative and engaging, and let me tell you, you have hit
    the nail on the head. The issue is something which
    too few men and women are speaking intelligently about.
    I am very happy that I came across this during my hunt for something
    relating to this.


    I was suggested this blog through my cousin. I am now not sure
    whether this submit is written by way of him as no one else realize such special approximately my difficulty.
    You're incredible! Thank you!


    进步淘宝客转化率的办法分享 中介买卖 SEO诊断淘宝客 站少团购 云主机 A5中包   我近来逢睹一个很年夜的费事,正正在运营的一个淘 seo 宝客网站出有转化率,那实的是一件很悲剧的工作,网站从拆建到如今曾经一个多月,排名有了,流量有了,可是出有转化,做为一个淘宝客网站 seo 去道,出有成交,那个网站根本上便是兴了。  我念能够有很多伴侣战我一样,有着不异的困扰,我采纳了一些方法,转化结果有所提拔,分享给各人,期望可以对各人有所协助。  第1、检测推行的淘宝商品  我是以专客的情势做的淘宝客,排止榜是必定要有的,此中,排名靠前的几个商品按理道 seo 该当是销量没有错的,可是适得其反,我不能不检测一下是否是商品呈现了甚


    Ayoo...!!Bergabung sekarang juga bersama Agen poker online terpercaya dan aman saat ini
    Sudah saat nya anda sekarang menjadi Milliarder
    Hanya dengan deposit 50.000 dan sudah bisa menjadi seorang MILLIARDER..
    Penasaran bukan gimana menjadi seorang milliarder??
    Semua jawaban nya ada di dengan JACKPOT GLOBAL 5 MILLIAR..
    Dan sekarang ini telah mengeluarkan promo yang menarik
    -Deposit 100.000 bonus 100.000 berlaku hingga kelipatan 1.000.000
    -Deposit 3x berturut turut mendapatkan bonus 10%
    -Komisi Referral 20%
    Ikuti terus & nantikan promo selanjutnya dari ya BOSS..!!
    Mentaripoker telah di support oleh bank : BCA , MANDIRI , BNI & BRI
    Untuk keterangan lebih lanjut mari hubungi team live chat kami yang sudah tersedia...
    Mentaripoker situs poker online pertama anti bot anti admin dan cheating

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>