PHP Email Schedule
Author
Discussion

thunderstruck

Original Poster:

8,879 posts

312 months

Monday 11th July 2005
quotequote all
Looking for a PHP script for the following.

User registers on a website, giving their birthday, which is stored in their profile in MySQL.

On the day of their birthday, system sends them an email.

Presumably this means I need a script that runs in the "background" checking the DB for birthdays today. Can this be done in PHP?

Many thanks
thunderstruck

zaktoo

1,401 posts

270 months

Monday 11th July 2005
quotequote all
You'd be better off using a cron job, and probably not writing this particular script in php, although php can be used for this. If it's all you've got, then do it in php without thinking...

Ciao

Zak

Plotloss

67,280 posts

300 months

Monday 11th July 2005
quotequote all
As the PHP is server side and you probably wont be able to schedule tasks at the webserver end all you'll need to do is write a PHP to submit a query to select records equal to today.

You should be able to create a scheduled task locally that launches explorer pointed at your PHP extract to achieve this.

It should be fairly simple to be honest.

thunderstruck

Original Poster:

8,879 posts

312 months

Monday 11th July 2005
quotequote all
This is about the limit of my knowledge! Cron jobs are written in shell script I believe?

If I was to do it in PHP, any ideas how?

Ta.

Plotloss

67,280 posts

300 months

Monday 11th July 2005
quotequote all
You'll need two PHP's

The first containing a form which submits in INSERT INTO to your mySQL file

The second submits a SELECT FROM table WHERE birthday = [today] then for each record in the result set sends a happy birthday email.

The second one launched from a scheduled task or just launched manually, daily.

thunderstruck

Original Poster:

8,879 posts

312 months

Monday 11th July 2005
quotequote all
Plotloss said:
You'll need two PHP's

The first containing a form which submits in INSERT INTO to your mySQL file

The second submits a SELECT FROM table WHERE birthday = [today] then for each record in the result set sends a happy birthday email.

The second one launched from a scheduled task or just launched manually, daily.


Cool, that sounds do-able. It's just the scheduled task bit that is stumping me at the mo...

Plotloss

67,280 posts

300 months

Monday 11th July 2005
quotequote all
Thats local, as in on your desktop.

So you would have a scheduled task which launches something like:

c:\program files\internet exploreriexplore.exe www.yoursite.co.uk/birthdays/extract.php

This will execute the second PHP at the server end to perform your extract/mail operation.

thunderstruck

Original Poster:

8,879 posts

312 months

Monday 11th July 2005
quotequote all
Excellent, thanks so much for that.

Is that something that could be run by a hosting company?

Plotloss

67,280 posts

300 months

Monday 11th July 2005
quotequote all
Nah, you'll need to handle the execution of the extract by having a local scheduled task which executes the extract PHP once daily.

You can either do this manually as a daily task or schedule it to occur once a day at a certain time if you have a machine that is on constantly.

All you are doing to create the extract is performing what is effectively a remote procedure call...

PetrolTed

34,468 posts

333 months

Monday 11th July 2005
quotequote all
Just used something like httprun ( www.icewarp.com/downloads/free.html?PHPSESSID=1cac622c1d7825dcb82d8f46c74918e3 )

to run a web page on a schedule.

Plotloss

67,280 posts

300 months

Monday 11th July 2005
quotequote all
Is that server side?

KITT

5,345 posts

271 months

Monday 11th July 2005
quotequote all
Is there a page on the website that's accessed at least once a day? If so then simply have some PHP there to check the dates in the database, and send emails out then. Remember to mark a record after an email's been sent, or they'll get one every time that pages is accessed on their birthday!

thunderstruck

Original Poster:

8,879 posts

312 months

Monday 11th July 2005
quotequote all
There's no page that is guaranteed to be accessed each day, otherwise no probs!

I found a very useful thing called "WebCron" : www.webcron.org/

It let's you set up a cronjob through a very simple interface, so I can now get it to run a script daily for me. Free too.

Thanks for all your help.

size13

2,033 posts

287 months

Monday 11th July 2005
quotequote all
If you can run scheduled jobs on the server, you can run the php page with the php executable (on whatever platform) without using a browser.

e.g.

php sendemail.php