John's Adventures

A Weblog Template With Mailing List

A screenshot of the weblog in actionRight, continuing my theme of weblog templates for use with CityDesk, I’ve gone another step forward. First of all, I wrote about a simple weblog template. This was a non-interactive template that created a simple weblog (oddly enough). Then I posted a weblog template with comments. This template included php commenting functionality to allow reader feedback of each post made. Now, in the (hopefully) final installation, I’ve built on that weblog template and added mailing list functionality. To make things simple, I’ll repeat the common steps from the comments system template article (so you don’t have to go and read that first).

Prerequisites

If you want to use my comments system on your own CityDesk site then you’ll need to have a couple of things. You’ll need to be able to run PHP scripts (check with your ISP) and also have the mySQL database installed on your server (again, check with your ISP). One thing to note is that if you want to test it you’ll need these installed on your own PC. You’ll no longer be able to use the preview option in CityDesk to see your site (as my scripts are .php and need to be run on a web server). I’m not going to explain how to install PHP and mySQL on a windows PC, but you should check out their websites (I’ve linked to them above) and follow their instructions. I found it to be pretty straightforward on my copy of Windows XP Professional though for what’s it’s worth.

The First Step

The first thing to do is download my CityDesk template:

Next, open it up and check out the variables (click View > Variables). You need to ask your ISP for the following values, although I’ve given a hint to what they probably are:

  • UserName – this is the mySQL user name that has access to the database.
  • DatabaseName – the name of the actual database.
  • Password – the mySQL user’s password.
  • HostName – normally ‘localhost’ but your ISP may have other ideas.

Next you need to input the location of your published site. In order that the mailing list functionality can work, you need to provide the valid URLs to the mailing list page. The required variables are as follows:

  • ContactEmail – your contact email address, when you send a mail out from your site, this is the address that will appear in the ‘from’ field.
  • WebsiteURL – this is the full URL to your website (to the index page), so that might be http://www.mysite.com/ or even http://www.mysite.com/myblog/ depending on where you publish to.
  • SiteName – the catchy name of your website.

Now that you’ve got that sorted you’ll need to set up a publish location – I’m afraid that the site won’t work if you hit the ‘Preview’ button as I mentioned above. Check out the CityDesk documentation to figure out how to do that (it explains it better than I ever could).

Create The Database Tables

Now you need to create the tables in your mySQL database. If your site has uploaded correctly and you uploaded to ‘www.mysite.com’, then browse to ‘www.mysite.com/createtables.php’. If all goes well and you’ve correctly configured the three variables I mentioned above, then all you should see is the message ‘Done!’. If there is a failure message or nothing at all, then I’d advise you to talk to your ISP. If they’re no help, then drop me a line.

All the script does is create the tables that the comments system uses. One, ‘ArticleIndex’ maintains how many comments each article has and the other, ‘ArticleComments’ holds the actual comments. Your mySQL admin tool should let you browse the fields, although they’re not very interesting.

Once the tables have been created, just browse to ‘www.mysite.com’ (well, whatever your site is) and the site should work perfectly. If it doesn’t for any reason then drop me a line, because it works perfectly when I publish it to any location!

Using The Mailing List

If you follow the link to the mailing list page, e.g.

http://www.mysite.com/blog/general/MailingList.php

then you will be presented with the sign-up page. If you enter an e-mail address then the address you enter will be sent an email containing a link to confirm the subscription. Note that until the person follows that link they will not receive any emails you send out to the list.

To send out an email to the list, browse to:

http://www.mysite.com/blog/general/MailingList.php?action=newmessage

and you will be presented with the composition page. Here you can enter the subject line, message content, a URL that will be included at the bottom of the email and your password (which you entered above). When you fill those fields out and click ‘Send Message’, an email will be sent to each subscriber to your list. At the bottom of each email will be a link that allows the person to unsubscribe from the list if they so choose.

The fact that the mailing list requires a subscriber to confirm their subscription means that only people with real email addresses can join (otherwise they wouldn’t get the confirmation message). I used code very similar to this on my own mailing list and it had absolutely zero problems. Good luck!

1 Comment on “A Weblog Template With Mailing List”

Thanks for making this available.

Leave a Comment