hi there, i am developing software that allows insurance companies to send text messages to their clients when their insurance expires. i want to add a function that allows the system to automatically send these messages n number of days before the expiry date. ('n' being number of days specified by the insurance company. for example:

if John's insurance expires on 25th november and his insurance company has set a date through the system that all clients should receive text messages 5 days before the expiry date. the system should automatically calculate the date and John should get a text message on 20th at 06:00 hours.

please help me. am using php,ajax and javascript. how can i do it. i know it has to do with javascript and time(duh)..

thanks

Hi.

How are you sending the text messages?
(I am assuming this is a message meant to be sent to your client's phone?)

If that is the case, you are probably going to have to use some external API to do this, or send a request to some phone companies message server. Unless you have the means to send this message from your server?

And you are probably going to want this to happen automatically, every day at a certain time?
Which would require something like cron (on Unix), or whatever you OS has to offer.

In the end, this will not be done with JavaScript. That is mostly used to create interactive websites and isn't really well suited for stuff like this.
PHP would probably be better suited for stuff like this.

I can't really tell you more until you tell us *how* you plan on sending this message.

Hi.

How are you sending the text messages?
(I am assuming this is a message meant to be sent to your client's phone?)

If that is the case, you are probably going to have to use some external API to do this, or send a request to some phone companies message server. Unless you have the means to send this message from your server?

And you are probably going to want this to happen automatically, every day at a certain time?
Which would require something like cron (on Unix), or whatever you OS has to offer.

In the end, this will not be done with JavaScript. That is mostly used to create interactive websites and isn't really well suited for stuff like this.
PHP would probably be better suited for stuff like this.

I can't really tell you more until you tell us *how* you plan on sending this message.

oh sorry about that. yes i got a deal with a company to send the text messages to the phones and i use php's file() function that directs to a web server with the message attached. if there is more than one client i use the looping mechanism to send the message. something like

$url = "http://000.000.000.000:8080/$message=Dear%80customer blah blah blah"

then i use file($url)

now i just need to know how i can trigger some kind of listener to check everyday at a specific time and send messages to clients whose insurance expires in a certain number of days.

thanks for all the help.

Ok.

Then all you have to is set up a scheduled execution of your PHP code.

What I would do is set up a cron job.
Cron is a Unix program that executes commands at set intervals.
Windows has a similar program that Microsoft (creatively) named Task Scheduler.

Would something like that be available to you?

This is of course possible with JavaScript, but I wouldn't recommend it. It would require you to have the page open on a browser 24/7 and that your PHP script be available via a HTTP server, which is an obvious security threat.

But... if you choose that path, look into the window.setInterval method. It is used to execute a function at a set interval (measured in milliseconds).
You could use that to trigger an AJAX call to your PHP script.

thanks alot for your help

please inform me more on using windows task scheduler because i think it would be much better for me.

in the meantime i will look into the javascript setInterval method but like u said it would pose a security risk as well as it having to be on an open page 24/7 which will make it hard for me.

but thanks for the help so far.

The ideal solution would be to set up a daily execution of a PHP script on the same server that hosts you website. But to do that you need access to that computer. Do you have such access?

The alternative is to create a web-based PHP script that you can execute either from the Task Scheduler on a remote computer. This is obviously less secure and will require you to create a program to send a request to your server.

I am not an expert on using Windows or it's task scheduler, but it is a GUI program so it should be easy enough to navigate. On XP the program is found in the All Programs -> Accessories -> System Tools menu.

hi, thanks,
i will create a program that can link straight to the php file that does this.
thanks for your help..you are a life saver!!!!!!!!!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.