--------------------------------------- START ------------------------------------------

Infinite Responder!

By Aaron Colman - 
aaron@ibasics.biz
http://www.ibasics.biz

Have you ever wanted a completely customizable autoresponder script?
Set the times you want? For as many messages and users as you want?

That's why I called it Infinite, because that's about what you get.
Actually, technically, you probably shouldn't go above a bigint(30)...
but that's still pretty dang big.

Infinite Responder is a cross between a newsletter and an autoresponder.
I call it a "multi-responder" since you can send as many responses
as you want to people the that subscribe. It also offers a subscribe
confirmation that verifies the email address (to reduce bounces) and
prevents 3rd parties from subscribing people without approval 
(eliminates spam worries).

With Infinite Responder you receive subscriptions via a web form
submit. It will process the submit and as sendmails.php is ran, 
will send out messages at a pre-programmed rate. You can set the
times anywhere between 10 years (or more) and 1 minute. The time 
field supports months, weeks, days, hours and minutes. The message is 
scheduled "from subscription" so if you schedule it for 1 hour, the 
message is scheduled for 1 hour after they subscribe. Each message
will only run once, rather than over and over, so you can plan a
responder campaign with ease.

If you need to send things in yearly increments (Good luck! Tell me 
how it goes, ok?) simply use the months option. In testing I tried
52 months (4 years, 4 months) and it was indeed scheduled for that time.

Please send all bug reports to aaron@ibasics.biz
Thanks!


--------------------
Installation:
--------------------

Installation can be tricky if your not atleast superficially 
familiar with unix, MySQL, and PHP. But for those that are,
it's a piece of cake.

If you need help with installation, I offer a professional installation
of this software for a mere $30. For more information write me at
aaron@ibasics.biz or visit the website at:
http://www.ibasics.biz


Requirements:
You will need MySQL, PHP and a way to schedule tasks. I have
a special section of this file dedicated to setting up a *nix
crontab. That is the program I recommend for this task scheduling,
but you can use any service that you find if it'll do the job.

I developed this on the following:
Apache 1.3.28
linux-2.4.20-29
PHP 4.3.3
MySQL 3.23.58

So the closer you can get to that, the easier it will be to install.


Intalling this package takes 5 steps:

1. Unzip into a new subdirectory.

2. Set up databases as defined in defs.sql
If you have one of those nifty control panel setups or a DB admin
program you can probably just copy and paste the query and get the
tables created to spec. Otherwise you'll have to load the file from
the command line tool or type it all in by hand (not recommended).

3. Edit config.php and make sure all of the variables are set.

4. Set up crontab. See the instructions below.

5. From there just start at admin.php. Enter the login and password
to load up the admin section where you can add your responders and 
their messages.

Unsubcribe message: To comply with Can SPAM and other legal measures, it's
important to have an unsubscribe message for any subscription-based system
that sends out emails. Originally I had these sent out automatically, but
then I decided to replace it with a tag.

Put:
%unsub_msg%

At the end of any message that you want to include an unsubscribe link.
The other tags can be found in the manual.txt!


--------------------
Supported Tags:
--------------------

Your messages can make use of certain tags.

For custom fields, should you chose to set them up,
it's the %cf_fieldname% where fieldname is the
name of the field in the custom table.

For standard data we've got:

%unsub_msg%  - The unsubscribe message
%RespDir%    - The responder directory
%SiteURL%    - The URL of the site

%subr_id%                 - The ID of the subscriber
%subr_emailaddy%          - Subscriber Email address
%subr_firstname%          - First name
%subr_lastname%           - Last name
%Subr_JoinedMonthNum%     - The number of the month they joined
%Subr_JoinedMonth%        - The text name of the month they joined
%Subr_JoinedYear%         - The year
%Subr_JoinedDay%          - The day
%Subr_LastActiveMonthNum% - The last month number they received a message
%Subr_LastActiveMonth%    - The last month, in text, that they've received a message
%Subr_LastActiveYear%     - The last year, same as above.
%Subr_LastActiveDay%      - The last day, as as above.

%resp_ownername%          - The responder owner's name
%resp_owneremail%         - Their email address
%resp_replyto%            - Their reply-to
%resp_name%               - Their name
%resp_desc%               - Their description

Some of these, like %subr_id% or %subr_emailaddy% work well when
building tracking links. This can be easily combined with something
like phpAdsNew and text ads to provide for full campaign tracking.

Others, like their first name and the date they joined help to
customize the messages. Others, like the responder owner's name
are there merely for convenience.


--------------------
License:
--------------------

After some thought I've decided to release this under the GPL.
I mean... why not? It's not like anyone is actually going to pay 
for this software when there are bigger, better and more expensive
alternatives. It's against the whole reason behind this thing... 
I'm fed up with expensive bits of software that didn't do the job.

You can find a copy of the GPL in this package as gpl.txt or you can visit:
http://www.gnu.org/licenses/gpl.html

I ask, altho I don't require, that you keep the "powered by" link at the
bottom. Why don't I require it? Well... honestly, if you don't want it
there then you're going to remove it regardless of how threatening the
license is. It's not like the code is compiled or anything... and notepad
isn't exactly hard to learn.

So why do I ask for it? Mostly because it helps my search engine ranking 
which in turn helps my business as web designer thereby allowing me to
find some way to make money from the time (4 days, off and on) that I put
into this project. 

I do offer professional installations of this package for $30 provided that
you have the required system (PHP 4.x and MySQL 3.x, mostly). I know that 
a lot of people won't need this, and that's fine... but given how cheap I'm
making it there's no reason to teach yourself MySQL, PHP and Linux just to 
install it. Your time is valuable.



----------------------------------------
Setting up this script via crontab:
----------------------------------------

Setting up the crontab:
Crontab is an program that runs the background of most unix servers. All it does it wait
for timing instructions and runs things according to the schedule. You can change your
scheduled crontabs by running

crontab -e

From a *nix command line. Also, a lot of hosts offer a crontab utility that gives you
access to the crontab from a control panel. Setting up a crontab isn't simple if you 
have no unix experience. It's doubly difficult as the standard editor is VI, a very
complex editor that is difficult for beginners to learn.

If you have MySQL and PHP on your server I offer custom installations for only $30.

Once you get into the crontab edit you need to figure out 4 things:
How often do you want it ran?
How do you want to run it?
And where is the file you want to run?
Where do you want output to go?

1)
The first is the most complex. There are 5 time entries to crontab.
The last 3 are day settings, and as they're not often enough for
this script we're going to leave them as just *'s.

This leaves you with:
minutes hours * * * 

Minutes is the minutes that you want to run the script on.
Hours is the hours.

Lets say you want to run the script at 3:30 every morning:
30 3 * * *

30 minutes at 3 o'clock, every day.

If you only want to run it every hour, do this:
0 1-24 * * *

That's at the zero minute marker of every hour.

Some people suggest that you run it constantly with:
* * * * *

But in my experience this risks putting a high load on your server if you
have a lot users, messages, responders or mails to sort thru. There are
1440 minutes in a day, there is no reason to run it this script 1440 times
per day.

Most of the time 10 minute intrevals are enough:
00,10,20,30,40,50 * * * * 

That only runs it 144 times per day, which should be enough and not put
too much stress on the machine.

If you've got a small list or need to check things more often try this:
0,5,10,15,20,25,30,35,40,45,50,55 * * * *

While that's a big long, it runs the script every 5 minutes. That's 12
times an hour or 288 times per day. 

2)
The second thing you need to know is how you're going to call the script.
You can set up a seperate shell script or CGI wrapper if you need to, but
again... if you don't have a lot of unix experience then doing this would
be very time consuming.

You can call the PHP file directly by calling PHP. Depending on how crontab
is ran, you may be able to do this by just using:
PHP sendmails.php

But that's not likely. You can also use lynx if you have it available with:

lynx -dump http://www.yourdomain.com/responder/sendmails.php

That works very well, but it does take some time to load lynx. This isn't enough
to stop you on a small list, but on a big list... or on a server without lynx,
you'll need to do it another way.

The easiest and quickest way is to call PHP by it's complete path name with:
/usr/local/bin/php sendmails.php

Again, that will depend on where your php is. You can find either lynx or php
with the whereis command. Just type:

whereis php
or
whereis lynx

From the command line. If you don't have whereis then ask your admin or tech support.

3)
Where the file you're running is. This is important because cron won't run things
from the directory you want it to. It needs the full path of the filename in almost
every setup. This isn't a problem. Just change to the directory with the file and
type:
pwd

And it should give you the directory name like:
/home/user/www
or
/home/user/www/responder

Then just tack on the name of the script at the end like this:
/home/user/www/responder/sendmails.php

Simple so far, right?

4)
Now, where do you want output to go?
By default, most systems will send it to your email address. You don't want this.
Why? Because you'll get an email each and every time it runs. Do you want 300 emails
per day telling you that it actually ran your crontab? Yea. I wouldn't either.

At the end of the filename this:

 > /home/user/www/responder/cron.log

And all information will be sent to cron.log
Or, if you don't want to use a file (I wouldn't, it takes up space)
just send it to a special "black hole" file.

 > /dev/null

Putting it all together:
Now just add all of it together.

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/local/bin/php /home/user/www/responder/sendmails.php > /dev/null

That runs your script thru PHP every 5 minutes and drops the the output into
the great void.

A convenient resouce for this can be found at:
http://htmlbasix.com/crontab.shtml



----------------------------------------
What to do if you don't have crontab:
----------------------------------------

The goal is to get sendmails.php ran. You can do this however you want.

If you have no life what-so-ever you can just run the file from your browser
every 5 or 10 minutes. I wouldn't choose that option. You can also include
sendmails.php like this:
include('sendmails.php');

In your index php. That will call it everytime someone pulls up your main page.
Another way to do this is thru an image load.

<img src="inf_resp/sendmails.php" alt="" width=0 height=0>

And put that in all of the html files you want. There are 2 problems with this:
1. Server load. If you have a lot of traffic then it'll kill your site.

2. Poor response time. If you have only a small amount of traffic then it'll
take a while for things to get sent out. This means that your message timing 
will be off, possibly by hours or even days if you don't get a visitor.

Of course if you don't have any kind of scheduler available then you've got no
choice.

----------------------------------------------------------------------------------------



--------------------
Editing files:
--------------------

Other than sendmails.php, which we'll discuss in a second, it's best to keep all of
the filenames the same.

Why? Simple. I didn't use ENV['PHP_SELF'] and for the immediate future I'm not
planning on changing it. Also, keep in mind that messages.php and responders.php
call each other all over the place to provide the responder-message interface.



--------------------
Template files:
--------------------

The template files (page.open.php and page.close.php) -

These are 2 template files, open going before and close going after
the responder's output. Use a php include from these files to include
your pages where-ever they should go. This'll let you integrate the 
responder into practically any design.



--------------------
Security Tidbit:
--------------------

Most of this script has been built for security in mind. It'd be pretty hard for someone,
even if they knew the admin password, to send an XSS to your subscribers. 
Not impossible, however.

SO. First, use 2 seperate and lengthy random strings in config.php. This will help 
to increase security. Also, be certain that you choose a good login and password.
By good I mean a combination of words and numbers. Admin123 much better than just
"admin". AdminDude314159 (admindude pi) is MUCH better. You get the idea.

SQL Injection: I've gone to some lengths to make sure that all post variables are
checked for this and filtered appropriately. The routines for this are in 
evilness-filter.php and unless you're comfortable with PHP, I wouldn't mess with them.

The HTML messages: The post variable that handles the HTML post isn't as strict with
HTML as the others. For obvious reasons. It doesn't convert < and > into &lt; and &gt;
entities as that would kill any tags you give it. This might open up a new hole, I'm
not certain. It DOES still filter out javascript so that most XSS bugs won't be a
problem. If anyone finds a hole here, please let me know.

Denial of service: Like all scripts, there's some load placed on the server when it's
ran. If you have a large list, you'll want to rename sendmails.php to something else 
(just be sure to update your crontab, too). This will make it a bit tougher for people
to lag your machine by constantly calling the send script since they'll have to find
the filename first.

---------------------------------------- END -------------------------------------------