Hi

I am very new to PHP so please forgive me for sounding noob

but what I want to do is provide a web-form for users to input to/from/message so that he can send an email using the form. that part is very easy with mail() but i am trying to add another function where the user can input a delay. So let's say he puts in his email contents and puts in a delay of 20 minutes. I want my server to send that email out after 20 minutes.

I have tried searching and I see people suggest cron jobs, which i cannot do cuz my hosting server is limited. I also saw sleep(). But wouldnt sleep() result in my code to continue executing until the delay time is met? because ideally after the user puts in 20 minutes and submit, the website should inform him "mail will be sent in 20minutes" and then return to original page with the form blank again, so if he wants he can submit another job.

is there anyway to do this strictly in php, no database(dont have one)??

Thanks

    I don't know of any way to do it without cron (and preferably a database). There are lots of hosting companies that will host your site, give you PHP, email accounts, cron and a database for $5 a month. It's worth it. You can learn a lot more about PHP and become a better programmer when you have good tools. I'm sorry, I know that's not the answer you're looking for but I don't think it can be done in any reasonable way without cron.

      ok...update...

      my hosting provides crontabs. (no database with my plan though)

      so currently i have a web-form which gets users input, and then it sends the results into a queue folder as a txt file, where i have a php script which I set it on executing every minute with cron to check if any of the files are ready to be emailed, if it is ready the script will move the file into an execute folder, where another script, also cron-ed for every minute, will email any files that is in that folder and then delete it.

      my question, i am running cron on 2 scripts every minute of every day, sounds kind of wasteful....and i am not sure if my hosting service will frown upon that and disable me, is there no other way?

        First of all, it's less wasteful than you think. It's not like starting up MS-Word and shutting it down once a minute (twice, actually). Cron is running anyway. It looks at your crontab each minute to see if you have any scripts that need to be executed.

        And executing a script once a minute is about as server intensive as pulling up your PHP based home page. So think of it this way: Instead of getting 10 hits a minute (which is so low it's practically zero), you're getting 11 per minute. Still basically zero.

        Now if you were getting 10 hits per second on your home page, that's a pretty good clip and many hosts will start talking about kicking you off... but two extra page loads per minute isn't going to mean the difference between getting kicked off or not.

        The second thing is this: You can reduce the two cron jobs into one. You said that one script moves the files from one directory to another and then another script sends out the emails. There's no reason why one script couldn't do both things. (Check this, do this, check that, do that). It won't save very many cpu cycles but it might make you feel better by cutting your number of cron jobs in half.

          haha yea ur right, i could combine the scripts into 1! doh! i am not that efficent of a coder...i'll prob do that tonight...so at least i tried to help my hosting service u know? heh

          alright then....thanks so much for the help!

            Write a Reply...