Question

I'm making a website that need's a cron job or a scheduled task to send emails weekly but the problem is that I don't know if the host supports it...

This website is for an institution and I can't put it in any other host...

The host is using Apache.

If it doesn't support, how can I send weekly emails automatically, without changing host?

EDIT

I forgot to say that I'm new in cron jobs.

Was it helpful?

Solution

Apache has nothing to do with cron jobs as the system running on the host must trigger the job (which then can invoke a script running under apache).

Do you have SSH access?
Add the job to the /etc/crontab file or the cron-file of your user.

Or do you have a Webinterface to some management software (e.g. Plesk)?
Search there for an option for Cron jobs or Scheduled tasks.

If not you can use some external services which will call an URL on you site to trigger the job like http://www.setcronjob.com/.

OTHER TIPS

First, ask your host if cron jobs are supported (they should be), check your panel (if there is one), try to set up one and see if it works etc.

If not, one possible way (other than to find an external service that will do the call to the script for you) is to add a function to your code that will be called every time a visitor of your site enters a specific page (e.g. the index). There, you will check if the weekday is the day that you want to send the e-mail. If yes, then send the mail, having a flag (e.g. a record in the db) to check if it has already been sent.

Of course it's not the ideal solution, all the others (the actual crons or an external service) are better, but since it is a solution, it's worth mentioning.

Have you read some documentation about cron-daemon? This code is check the the cron is running

ps -ef | grep cron

After then you need to create a file which can handle the email address pickups and send th mails.

And also need to add something like this to the cron (it just an example send out something at every sunday, 23 o'clock):

0 23 ? * 0 php /path/sendnewsletter.php
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top