Archives

Setup a Mailing List

Posted in: Web | Tags: , , ,

Apparently nobody needs to know how to setup a mailing list anymore. Try checking google, there’s not much to look through, unless you know what your looking for. A client wanted a mailing list, so this is what I found. The IMAP extension for PHP is what you need. Here is the basic script that I found to work:

<?php

$subscribers = “you@gmail.com, sub@scriber.com”;

//Open a POP3 Inbox
$stream = imap_open(“{localhost:110/pop3}INBOX”, “username”, “password”);
//Get the content of the first email
$content = imap_body($stream, 1);

//Send the mail to your subscribers
mail($subscribers, “Subject”, $content, “From: me@mysite.com”);

//Delete the Email so the script is ready for the next time
imap_delete($stream, 1);

?>

You have to setup an email account somewhere, preferably on your webserver, that would be the easiest place to get access, and send an email there. Run this script and it grabs the email and sends it to all of your subscribers and deletes the email so that it’s empty for the next time you send the script.

Now obviously you wouldn’t want to store the list of your subscribers in the script. I’ll end up storing them in a database and pulling all the email addresses out when I call the script.

Remember, this will only work if you have the IMAP extension installed on your server and you have to run this after you send the email so it might be a good idea to setup a cron job to run this at least a couple of times a day, depending on how important the emails are that you are sending out and how time sensitive they are. For a regular mailling list that is sent out weekly or maybe even less frequently than that a couple of times a day should be just fine. If you are going to use this as a listserv, you might want it to run more like once a minute.

Jun
07
2008

Leave a Reply