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.
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/.
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
Related
Is it possible to schedule a task with PHP? like, I want to choose a date with the jQuery datepicker, and submit it. When that date equals today's date, an email will be sent for example (or any other PHP script). The date will be different depending on the user, also, every user can have a number of scheduled tasks to run.
EDIT
The OS is Linux, and the website is hosted on godaddy.com
Also, it's the end users who will choose when to run these tasks, so they can use command lines for that.
EDIT
Any Ruby on Rails or Django solutions are welcomed as well.
If you're using a Unix server, try at.
http://www.manpagez.com/man/1/at/
It works in a similar way to cron, in that it's totally separate from PHP, and you need to shell_exec() an external command. However, it has a simple command-line interface. Like cron jobs, at jobs survive reboots.
If you use at you'll have to write a separate script to perform the task you want scheduled.
Example:
shell_exec("echo 'php script.php' | at -t 201208011234.56");
Will run script.php on August 1st, 2012 at 12:34:56.
You need some process in the server side to run the task at the scheduled time.
A popular approach is to store the task information in some database and have a cron job checking the task queue from time to time - it is very reliable and safe.
It is impossible to give a better answer without more information about the environment where it will be deployed. For example:
target OS
hosting type (dedicated, shared, cloud)
do you have administrator privileges?
is it exposed to the internet?
Most likely you will not be able to do that in a shared hosting environment, anyway, but I must say that having a website calling shell_exec is not very wise from a security standpoint, so I would avoid that if the site is exposed to the Internet.
A good hosting provider should have some kind of background task scheduler available, even if it is not crontab. If your hosting provider hasn't, trying to pull some stunt to fill the gap probably is a bad idea.
[update]
As I said in the edited part of the original post, I'm hosting it on godaddy.com, and I can't let the clients run these command lines etc. Is there a solution with other languages too?
I'm not hosting at godaddy anymore but they used to have a "Cron Manager" at their control panel. I think the correct goDaddy cron setup is
/usr/bin/wget -O - -q "http://yoursite.com/cron.php" > /dev/null 2>&1
at the Command Option in the Cron Manager. This "cron.php" will check the task queue to see if there are any email to send (the task queue being a simple table in your database where you will record any task scheduled by your customers).
You can do this without cron by simply adding a check into the main index page, or a standard include file - but that's only for when you really can't get access to cron (e.g. shared hosting). In this check you'd grab the list of outstanding actions and execute them, possibly by using
if (time_since_last_run > 5*60) // minutes
shell_exec("/usr/bin/php /var/www/check-tasks.php &");
The best solution is to use cron to launch a PHP script that will check for scheduled items within your system and execute them. You can either do this via wget or directly via calling PHP.
One shared hosting site that I have is externally scheduled from another of my servers via cron and wget http://othersite.example.com.
example crontab entry:
0 * * * * wget -O - -q -t 1 http://othersite.example.com/cron.php
I have found that there is related topic.However, there are some difference because the people is asking for ubuntu server but i am using the Apache (xampp****) the latest version, so are there any method to let the system automatically send mail by checking the date ?
Can it applies to some schedule sending as well? thanks
I have the script for sending it , the only thing i need is how to schedule send.
Edit:
Make it simpler , assuming only windows is the only platform. Can i do some php script and create the cron job in os , so that my client can schedule their mail in my system instead of doing it in the os?
3 rd party cron job is good suggestion but there is limitation (what if their service break down etc...) and i want everything is based on own system
If your xampp is on Windows, you can use windows-schedulers to call a particular script (PHP script in your case, preferably by an URL), which checks the birthdays of all the users and sends them mail accordingly.
If your xampp is on Linux/Unix/etc, you can use cron-jobs, and rest is same!
There is also a third way, a third-party scheduler or say online-cron, which will remotely call yours script (php-page).
Example:
If you are doing the cron-settings of OS yourself, you can still let the configure as to whom to email in your system, rather than OS.
After all, a cron so is to do something repeatedly, in your case, its just calling your scripts, by an URL.
Now regarding the time settings, you can make the CRON call your script every hour, and your php script will check the appropriate time, and fire the mails!
schedule a script in crontab or scheduler which will check the birthday of your customer
and send them an email
this script will run everyday at particular time of the day
use server cron job to run a script that will send out email. ur script should compare current's date and customer's birthday date.
You could use a cron-job. With PHP that get all the people that you want to send an email and gets template and send it just substitute the name and other stuff
You may use Wishing Application. Getting started provides good details on how to kick started. At minimal you need only two things the excel file having wish details (Birthday and on work anniversary), and a configuration file (application.properties) to provide the mapping details and other configurations. There are various options to run this application, locally (background, foreground, docker, windows-scheduler etc) on cloud
Disclaimer : I am the owner of application.
We are running a webinar. I want to send reminder email to all those registered on my site 3 days before the webinar.
The registrant details are in my MySQL and it is a PHP website.
How do I do that?
Any help would be highly appreciated!
Thanks,
PHP can't do that by itself as it is not a program running constantly on a server. It is only run when a user requests a web page. You would need to set up a cron job on the server that calls a PHP script to do the emails.
First, your database would need a field that says whether you have already sent the email or not. Your PHP email script would check if it is 3 days or less until the event, and you have not already sent an email to that person, then send it.
Then you would call that script from a cron job. You can run PHP from the command line, or alternatively use something like curl or wget to fetch the URL as if you were running the script in a web browser. (That would also mean you can run the cron job from another computer if necessary.)
You could set a cronjob to run a reminder script at a specific time 3 days before your webinar. Your script would loop through your user data and send email using some variation of php's mail function.
Not sure what your server type is but if you are running cPanel here is a link to their docs on how to set up a cron job:
http://docs.cpanel.net/twiki/bin/view/AllDocumentation/CpanelDocs/CronJobs
Let us know which of the above you're not sure about and we can provide some more info.
PHP doesn't have built-in schedulers.
You should consider using cron on unix/linux
or
Schedulers on Windows
or
There are some online crons available.
which will call your php-scripts. (which will internally do the task of mailing)
Note: the links above refer to drupal sites, but explanations given there with regards to cron and schedulers are applicable in pure-php.
I Have a system which is managing the document authorization on different hierarchy level, In this i need the system to automatically mail to the user for some reminder/notification before 3 days of expiry, I am using PHP MYSQL APACHE
How can I Achieve this?
make a script, and let cron job do the automatic email sending for you
Or you can use Swiftmailer
You can really only do this with Cron. If your server is a Linux host, you can schedule a PHP script (which you'll need to write) to run at a set time, e.g. every minute. Your script will check against the users database, select any users that are 3 days from expiry and mail them. Setting up cron is host-specific and your hosting provider might not even let you do it. Usually you'll have some server administration software (e.g. cPanel) that will let you schedule a cron job and specify which script to run. If you have SSH access, even easier - you can just SSH in and run crontab -e to set up a cron schedule yourself. There are plenty of cron tutorials on Google.
Check with your hosting provider if they allow scheduled activities.
I want to a e-cards or something like that. The user can choose the e-cards, after chosen, he must enter the some fields like name(to and from), email(to and from), message and I want to let user to choose which date to send the e-cards.
How to send the e-cards on specific day? I need to write a script that run every new day? How to do that? Sorry, I am new to php... (but not beginner like not even know how to execute mysql query, get message from url etc)
Yes, you need a script that runs every day. (Barring ridiculous maneuvers like trying to fake this by checking on Web requests.) The usual way to do this in a Unix context is called a cron job; if your hosting provider is Unix-based, you should look into what they provide for making cron jobs available to you. On Windows there's a parallel service called Scheduled Tasks.
A similar question was disscussed here resetting-a-mysql-field-value-without-user-execution
I'll just reiterate: There are web based cron services too. This could come in handy if you only got a shared hosting plan and can't add cron jobs. They will call an URL at a regular interval that you can set. Usually very cheap. (Cheaper than upgrading to a root-access server anyway.)
Just search Google for web based cron
ciao!
/0
This is for *nix.
Let's say you have a php script that sends email on a specific day called mailer.php
<?php
//mailer.php
if (date("m/d/Y") == "06/02/2009") {
mail("client#email", "Subject", "Body");
}
?>
We are going to assume that you already have cron daemon running in the background.
If you have root access to your machine, then setting up a cron job is simple as editing a file.
Open up /etc/crontab file and add the following task:
1 14 * * * root php /path/to/your/scrip/mailer.php
This means, as a root, the mailer.php script will be running daily at 02:01PM. You can change the numbers to whatever you desire.
This is somehow complex. First it depends on your system. If it is Linux/BSD/Unix/Solaris then you have this handy utility as cron. If you are using Windows, you have Scheduled Tasks. Run your script daily (or as you wish) and check what cards you have to send today.