Site Links
Blogs
Affiliates
In This tutorial I will show you a simple way to send out a Happy One Year Anniversary email.
A majority of my projects require lots of email notifications and I don't have time to look at my data base everyday and see who needs to be emailed next. Thanks to Cron Jobs this task can easily be accomplished in your sleep.
Lets say im running a forum and I want to thank all my subscribers for being loyal readers, but I only want to send them this email each year. I first want to create my Cron Job, im going to go with the Standard setup. So log into your control panel and locate Cron Jobs. You then might be prompted to select whether you want to go with Standard or Advanced (Unix Style), click Standard. You now should be in the Cron Manager.
Next enter your email into the cron output field.
Then in the command line you want to add
/usr/local/bin/php -q /home/user/public_html/cron/mailer.php
If you do not know your public_html path you can add <?php phpinfo(); ?> to your mailer.php file which will display all your php information. Find the SCRIPT_FILENAME row and copy the path from there
As you can see im going to put my php script in a folder called cron in my root
Now we want to tell the cron job how often to run this script. Since we only want to run this once a day we want to set the minutes to 0, hour to 1 am.
When you are done everything should look like this.

Save and then lets move on to the php section of this tutorial.
In your root directory you want to create a folder called cron, then create a new file and call it mailer.php In your mailer.php file lets create a function that sends the email.
Now we want to create another function that checks the database for dates_joined that are one year old. Then if the date is one year old run our sendEmail function to send out our anniversary email.
Here is a basic table structure of what my database table looks like. Since im writing this tutorial on 2009-10-21 im going to set my date_joined back one year for testing purposes.
| id | name | date_joined | |
|---|---|---|---|
| 1 | Brandon | brandonh@hollen-b.com | 2008-10-21 |
| 2 | Dan | dan@hollen-b.com | 2008-10-22 |
| 3 | Bob | bob@hollen-b.com | 2008-10-23 |
If everything is set up correctly our Cron Job should run once a day and send out our one year anniversary emails.
Please report any errors so I can fix them. For full script check out my google docs in these links below.
Links:
Create Database Script
mailer.php script