Events auto-reminder x number of days before event

3 posts by 3 authors in: Forums > CMS Builder
Last Post: July 4, 2012   (RSS)

By Mikey - July 4, 2012

I'm building an events list for a website and I need to create a sign up form for site visitors to sign up to receive an auto-reminder email message X number of days before an event takes place. Has anyone build something like this that could shed some light on how to build it?

Thanks, Zick

Re: [zick] Events auto-reminder x number of days before event

By gkornbluth - July 4, 2012 - edited: July 4, 2012

Hi Zick,

I did a similar thing to send remind emails to members that their renewals were coming up 30 days and 7 days ahead of their account expiration date (expiresDate). I ended up running a cron job to activate the process.

The values for first and second reminder days and messages are from text and text box fields in a single record editor called common_information

The reminder email script is attached.

Here's an article from my CMSB Cookbook thecmsbcookbook.com on setting up Cron jobs for CMSB.

CREATING A CRON JOB

Cron is a time-based job scheduler in Unix-like computer operating systems. The name cron comes from the word "chronos", Greek for "time". Crontab jobs allow users to schedule when a particular script is executed based on matching month, day, hour, and minute.

I’m using a crontab job or “cron job” to schedule when a PHP “membership renewal reminder” script is run.

The PHP script, which is run once a day, compares the expiresDate with the current date for each member. If the number of days until expiration matches a preset number, the member is sent an email reminding them that their membership is about to expire.

Crontab jobs are pretty particular in how they’re set up, and ISPs differ in the way that you access and input the information to set up a cron job, so you may have to get in touch with their tech support to get things operating as they should. My ISP (IXWebHosting) sets up cron jobs in the ftp management section of their interface.

There’s specific syntax for entering the scheduling information into a cron job request. At the end of this recipe, you’ll find the acceptable parameters from my web host IXWebHosting, taken straight from their “help” screen.

NOTE: You'll have to insure that the script that you're trying to run with the conjob has write permission

CREATING AND RUNNING A CRON JOB
There are 3 pieces of information necessary for creating and running a cron job
1) the scheduling information
2) the path to your server’s php interpreter (obtained from your web host), and
3) the path to the php file to be executed

I needed to run my script once a day at 2 minutes after midnight, so my scheduling parameters are:
Minute: 2, Hour: 0, Day of month: 1-31, Month: 1-12, Day of week: 1-7

After you’ve set up all your scheduling parameters, either put both the path to your server’s php interpreter, and the path to your PHP script in your crontab command line as in this example (Note: The path to your server’s php interpreter will be different, so check with your web host, and don’t forget the space between the 2 segments.):
/hsphere/shared/php5/bin/php -q /your_server_path/mailtest.php
or, put the path to your server’s php interpreter at the very top of your php script with no blank spaces or lines before it, like this (note: The path to your server’s PHP interpreter will be different, so check with your web host.):
#!/hsphere/shared/php5/bin/php -q

And insert only the path to your php script in the command line, like this:
/your_server_path/mailtest.php

TESTING SENDMAIL
To test if your sendmail is working you can create a .php file called mailtest.php with this simple php sendmail test script. When you refresh the page it should send the email.
<?php
$to = "your_email@your_host.com";
$from = "you@sendmail_test.com";
$subject = "Testing Sendmail";
$txt = "Testing Sendmail from PHP Script";
mail($to,$subject,$txt,"From: $from", "-f$from");
?>

TESTING YOUR CRON JOB
Once you’re sure that sendmail is working, you can use the script to test your cronjob.

CRON JOB CONFIRMATION EMAILS
More than likely, your Cron Daemon will send a confirmation email to an address you choose and you can use the information in that to debug your cron job and your scripts

Once you're sure everything is working, you can send the daemon emails to a non existent email address so that they will not clutter up your inbox.

Hope that helps,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

reminder_email.php 4K