Jump to content

Date triggered Email notifications


cjbeck71081

Recommended Posts

I am developing a CMS for a client who is interested in allowing every day people who sign up to be part of the system to put property listings online.  The client wants to be able to notify the person who placed the property listing when thier property has been online for 30 days, that they must renew the property by updating it's details.

 

Anyone have any ideas, where i might be able to head, or what this is even called?  Server Triggered Email Notification?

 

As well, if they have not updated thier information i would like to take thier listing down.  I figure I can use the timestamp, but I wondered if there was a better method.

 

 

Link to comment
https://forums.phpfreaks.com/topic/123012-date-triggered-email-notifications/
Share on other sites

This seems like a scenario where a cron job does the work perfectly. Your listings in the database should have a "date" field which stores the date when the listing was added. Then the cron job just checks if that listings has passed 30 days and send the email to the author. A sample code:

 

<?php
$member = '[email protected]'; //the email of the users, retrieved from the database
$date = '2008-09-06'; //this will be retrieved from the database
$nextdate = date('Y-m-d', strtotime("$date +30 days")); //calculate the date after 30 days
$today = date('Y-m-d'); //the actual date
if($today > $nextdate){ //if the 30 days period has passed
    mail($member, 'Listing Expired', 'Your listing #4453 has expired. Please renew it');
}
?>

I think I would use a unix timestap simple Examples:

time();

//OR
strtotime("now");

 

Then all you need to do is subtract the two (time in db, and now) to get a difference (in seconds).

30 days = 2592000 seconds

 

just divide 2592000 by your your difference to get days... I think... You my need to mess around with the subtracting and dividing.

Yeah, you basically set exactly when you want your script run, and the server triggers the running.  Ex:

 

0 0 * * * /usr/bin/php -f /home/DarkWater/somescript.php

 

Would run "/home/DarkWater/somescript.php" every day at midnight.

 

P.S:  4000th post! :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.