Automatic emails before account expiration

5 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 14, 2012   (RSS)

Hi All,

Using the website membership plugin, I ’d like to be able to automatically send an email to a member x days before their membership account expires (using the expiresDate and email fields in the accounts database) and then to send them another email on their expiration date.

I was wondering if anyone has worked up anything like this and is willing to share?

Best,

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

Re: [gkornbluth] Automatic emails before account expiration

By Dave - April 27, 2012

Hi Jerry,

It's always a bit tricky to send emails at set intervals and track it, but here's one way:

- You add a checkbox called: preExpiryReminderSent
- And add a checkbox called: expiryReminderSent
- You make a php script that runs as a cronjob once daily
- You load all the users where (this is pseudo-code):
(expiryDate - x days) < NOW AND preExpiryReminderSent != 1
and for each user send an email and then set the preExpiryReminderSent =1
- Then load all the users where (this is pseudo-code):
(expiryDate) < NOW AND expiryReminderSent != 1
and for each user send an email and then set the expiryReminderSent =1
- Then when they renew set both those checkboxes to 0

Note: When testing email code, test it well and output the results to the screen first with "Sending reminder to email@example.com" so you can work out any bugs without spamming your users.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [gkornbluth] Automatic emails before account expiration

By Dave - May 14, 2012

Hi Jerry,

For the PHP headers, are you able to specify the command line that calls the cronjob script? If so you can add -q to supress PHP's HTTP headers. Like this:
php -q /path/to/script.php

That should remove the powered by and content type headers.

For the PHP notices, a workaround might be to edit /lib/init.php and add this line just above "// define constants"

error_reporting(E_ALL & ~E_NOTICE); // show all errors but notices

// define constants


Let me know if those work for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Automatic emails before account expiration

By gkornbluth - May 14, 2012

Thanks Dave,

That worked perfectly.

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