Configure Scheduled Task in wamp Server [duplicate] - php

I want to schedule sending of email from php script. I want user to specify date and time and then on the specified date and time, I want those emails to be sent automatically. How do I implement it? I am working on codeigniter.

One way to do it would be to create a "scheduled_emails" database table. Put all the emails you want to queue in there, including columns such as, recipient, subject, message and optional headers.
You could then set up a script to look at that table and send any emails that have a "send_time" which is greater than the current time. You could then set up a cron job to run this script every.. 5 minutes for example.

PHP usually uses an external scheduler for this sort of thing. That means cron on *nix or Windows Task Scheduler on Windows.
If you want to set it up through a web interface, then you might consider storing your schedule in a database and having cron (etc) kick off a script that looks for overdue emails every 5 minutes.

Related

How to automatically call a php script every day to send out automatic emails

Is there a way where I can automatically call a php script after a specified interval.
I have a php script(say remindusers.php) that uses mysql to query a database where people have submitted their weekly reports. This script automatically queries the database and sends an email reminder to people who have not sent in their weekly reports yet.
What I am now supposed to do is give the ADMIN an option to set a reminder start and reminder end date during which calls should be automatically made to my remindusers.php script and cease on reminder end date.
What I learnt from SO/google is that I can setup cron (in LINUX) to automatically call my remindusers.php, but I dont have any shell access to do this.
Else Can I write another php script to essentially sleep every 24 hours and automatically wake up to call my remindusers.php script.
Are there any other built-in methods ?
Any ideas?
Use your site's visitors to trigger the event. Send a message and then check if 1 day elapsed. Then send another. You still need to pay attention not to double/triple/... send deu to synchronization.
When the time has elapsed use a MySQL (or system) MUTEX to ensure only one send occurs.
Yes you can! What you need to do is to use cron jobs. Cron jobs are essentially telling the server to execute a script (PHP or otherwise) at regular intervals. Cron jobs are very powerful and customizable, as you can set virtually any interval for your cron.
If you are using CPanel to manage your site, there is a button in CPanel to view all the cron jobs you have set. There is also a tutorial on that page.
Hope this helps.
Try with this PHPCron
PHPCron is a simple PHP script which lets you run multiple tasks on a schedule or timer. It can be run either from the command-line or via a web browser. Its behaviour is very similar to the popular cron program for UNIX.
http://katyscode.wordpress.com/2006/10/17/phpcron-running-scheduled-tasks-from-php-on-a-web-server/
I understand that you don't have Shell access but have you had a look at the cPanel to see whether there is an option to setup a cron job in there?

is cron job what should be used in this case?

Here is the 'use case':
Admin goes to the newsletter.php, fills in the form for email, i.e the subject, group of users to whom email is sent, writes the message and clicks the "Send" button.
Problem:
The number of emails sent per hour should be limited to, let's say, 400. That is, one email should be sent approx. every 10 seconds. Besides, sent and not sent emails should be tracked.
Question:
Will cron job do the trick?
The code is written in Yii framework. Is it possible that cron job will be activated when the user clicks on the "Send" button or only in the command line?
If cron job can do things above, can it be activated only in specific action of specific controller? or it affects the whole script?
Thank you
1- Yes it is a cron job.
2- You can do it in Yii refer to ConsoleCommand. Don not know how much do you know about cron? but make a script using consolecomamnd which runs every 10 secs, gets a singe email address in the queue and sends email to that address + removes it from the queue.
3- Yes in an action just build a queue (hint: mysql table) with the email address you need
I think you have the concept of a cron job wrong.
Think of the process this way:
Admin presses the send button.
...That script creates a queue i.e. adds email address's etc to a database table lets call it Queue. And finishes.
You setup a cron job to run every 5 minutes for example.
...The cron starts a PHP script which processes X entries from the Queue table, sends those emails, removes the entries from the queue table, and stops.
...The cron job starts again automatically after 5 minutes and repeats the process...
All you have to do is work out how many emails to send in each execution of the cron job, and how often to run it, so you dont exceed your limits or get flagged as a spammer.
My suggestion is that if you wanted to use cron to do such a thing, you would want your newsletter.php to write out a file to disk or database which contains the list of users. You would write a simple PHP script which would be triggered by cron which would be responsible for calling sendmail to send the messages. As each recipient is mailed you script would remove them from the list.
Alternately, you might want to look into some basic mailing list software. These often support a notion of throttled message sending.
I assume you are trying to manage limits imposed by your hosting provider related to number of emails sent per hour (antispam controls)
Yes cron jobs can be used in such a scenario. I personally have developed newletter systems which use such methodology. However, I send 350 and do a cron job every hour.
You should check if there are any emails to be sent on the first line and leave the cron job running every hour. There is no need to activate the cron job when the send button is clicked
cron itself just runs programs on a schedule. It doesn't have any logic in it that can know whether somebody clicked on a button, or logic that can know how many emails you've sent this hour, or which emails have or have not been sent.
cron runs under the control of a daemon. Although you probably could enable and disable it through a controller, you probably don't want to do that. If you're using cron, you usually need it to run all the time.
Instead, put the logic and the constraints into the program that cron runs.
if you can use system or exec function you could call cron job or any thing else in terminal can do it
for example system("ps aux | grep crond");

Sending Mail automatically at a particular time?

I am going to add one module to my project this module is about remainders.If today's date is a birthday of a person then a mail must be send to that person automatically at 9.00 A.M
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 our, and you php script will check the appropriate time,
and fire the mails!
Reference: Send mail to different customer on their birthday
Hope this helps..
You could always add a cron job/scheduled task that runs at 9 am and hits a service that checks if any mail needs to be sent out that day.

Send mail to different customer on their birthday

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.

how to trigger a function on defined date

i am doing a project where i need to notify a user through email if his account has expired,
that is when a user signsup his sign up date and expire date is inserted into the database
now what i need to do is , i need to fire a function when the users expire date is passed
and send an email notifying user about the expiration of his account .
and this needs to be done automatically through the function .
how can i achieve this ?
The simplest thing to do is create a basic cron job that runs on a regular interval (like hourly or daily) that runs a PHP script that queries the database for any newly expired users and then emails them.
You can have a cronjob that runs every hour or so (or quicker if you need to). This cronjob would run a PHP script that gets a list of all expired accounts and sends emails to them.
Here's a tutorial on how to use crontab.
Here is a SO question on Cronjob and PHP
Getting started with cron jobs and PHP (Zend Framework)
Timed Tasks (cron-like) in PHP
PHP: running scheduled jobs (cron jobs)
What is the best method for scheduled tasks in PHP
Write a cron job (running as often as you think appropriate) to call a script (possibly PHP CLI) that does a select for all expired accounts and mails them. And what does this have to do with JavaScript?
Probably the easiest way to do this would be using either at or cron. Either one of these could be set up to call a PHP or whatever script at the time of expiration, or it could be just run once an hour, each time checking if there are any newly expired entries.
A less efficient approach would be to have the header or footer script of your pages to check the database every time any page is loaded, but I would not recommend this approach unless you absolutely can't use cron or at.
By the way, if you are not using a unix / linux system but a Windows one, you could use Scheduled Tasks and call a script.

Categories