/    Sign up×
Community /Pin to ProfileBookmark

Time Ranges In IF or ELSEIF

Is it possible to specify a PHP program to send an email if an upcoming event lies within a specified range of time (such as 5 days) using an IF or maybe an ELSEIF statement?

If someone could show me how to do something like this I would greatly appreciate it. ?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@Ax_SlingerlandauthorMay 31.2011 — Awww, come on... Nobody any ideas about this? Even a hint to get me pointed in the right direction might help.
Copy linkTweet thisAlerts:
@NogDogMay 31.2011 — To directly answer your question:
[code=php]
$now = time();
$start = strtotime('2011/05/30 00:00:00');
$end = strtotime('2011/06/03 23:59:59');
if($now >= $start and $now <= $end) {
// do something
}
[/code]

Whether that is actually the best solution for your particular requirement may be a separate question. For instance, it may be better handled in a database query, if the times in question are retrieved there -- perhaps along with a flag field for each record that indicates whether or not the email has been sent yet.
Copy linkTweet thisAlerts:
@Ax_SlingerlandauthorJun 01.2011 — Perhaps a little background information would help... This is for a NASCAR Pickems game a friend of mine and I put together. I had a game layout and knew how I wanted it to work, but I have pretty basic programming ability so I had no idea about how to make it do so. So a friend of mine wrote it up in PHP and it works wonderfully. In fact, the only problem it has that I haven't figured out is how to make it sort the winners by points won properly. It puts people with less than 9 points ahead of people with 10 points to 99 points, and those people ahead of people with 100 points or more. Unfortunately my friend is too busy with his new business to help me with this anymore so I never got that fixed. (I'm used to that quirk now, but it sure would be nice to figure that out too... )

The email thing is a reminder for players to get their picks in on time. I figured it out pretty much by asking him questions and reading about the php mail command on the php.net website. It works ok as it is, but it sends out emails every week whether there is a race that week or not. That is what I am trying to figure out how to do. Stop it from sending emails in the weeks when there is no race.

Here's the code I am currently using, edited slightly for posting on the open Internet with ever present spammers, scammers, hackers, etc. lurking about:

<i>
</i>&lt;?php

$schedule = file('race_schedule.txt');

foreach ($schedule as $line){
list($date, $location) = explode('|', $line);
$races[strtotime($date)] = $location;
}

ksort($races);

$today = strtotime('today');
foreach ($races as $d =&gt; $l){
if ($d &gt; $today){
$next = $d;
break;
}
}

$to = "pickems_player@email_address.com";
$subject = "Racing Pickems Reminder";
$body = "Hey NASCAR Fans!nnThe next NASCAR Sprint Cup Series race will be:nThe $races[$next]nBe sure to get your picks in on time. The Pick Window closes at 6:00 AM Eastern Time on Race Day.nnTo have your Email Address removed from this reminder, just let me know.nnThanks";
$headers = "From: reminder@email_address.com";
mail($to, $subject, $body, $headers);

?&gt;


The file referenced by $schedule (race_schedule.txt) is just a simple text file written in this format:

2011-05-07 7:00:00|Saturday, May 7th.

2011-05-15 7:00:00|Sunday, May 15th.

2011-05-29 7:00:00|Sunday, May 29th.

2011-06-05 7:00:00|Sunday, June 5th.

2011-06-12 7:00:00|Sunday, June 12th.

2011-06-19 7:00:00|Sunday, June 19th.

2011-06-26 7:00:00|Sunday, June 26th.

And of course, there are as many dates as there are races. When a date and time has passed, such as 2011-05-29 7:00:00, it will use the next date that will occur, and put the text on the opposite side of | into the body of the email. Which in this case the date and time would be "2011-06-05 7:00:00" and the text placed in the email would be "Sunday, June 5th."

Once the program is set up and uploaded it needs something to "trigger it" every day. I had a php program that would do that with chron jobs, but my current website has lame chron job policies so I trigger it with the task manager in a message board. I have it set to send emails on Wednesdays, Thursdays and Fridays, for races that mostly happen on Sundays, but there are a few on Saturdays.

If you have any ideas on this setup I would appreciate your input. In the meantime I will play around with the code you posted and see what I can figure out.

Thanks!

Ax
Copy linkTweet thisAlerts:
@Ax_SlingerlandauthorJun 01.2011 — Oops... I forgot to say that the server is running php 5.2.17. Sorry...
×

Success!

Help @Ax_Slingerland spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...