how to use send mail when an event occurs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

how to use send mail when an event occurs

Post by itsmani1 »

i want to use send mail function of php on some event like new year etc. (i want to send email on 1st jan how to do that) i have problem in mail funciton and its use but how to intigrate it with time/event.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

1-) write a script that sends the emails.. (don't care about timing or things like that)

2-) if you are on a linux machine, lookup the "at" command. or "cron(tab)". on a windows machine you need the "task scheduler?". And schedule the script to run at newyear ;)
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

are you sure in this way i will be able to handel my alerts. actually my requirements are:
some one add or delete on the system, now what i want is : if the alert is present on the system and its time of execuation has come it has to be executed and i did not found any thing available in php for tht till now.
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

itsmani1 wrote:... i did not found any thing available in php for tht till now.
to make it simple, like Tim said, use crontab. Have your alert script executed once a day. It searches on database for event.. Each event has date entered into the database. If the date matched with today's date -> send email.

If you are advanced, instead of running the script everyday and search the whole table on datbase looking for today's event, you can write script to add to crontab for every single event. PHP only cannot write to cronjob log if it does not allow to use shell command, but you can use PHP and include cgi using virtual function. The rest on how to write to the log - I don't know how :)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

the easiest is to generate a file with all the jobs in...
and then `crontab $nameoffile`; to load all the jobs..
Post Reply