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.
Asked
Active
Viewed 4,407 times
-2
-
I am having email script in php but I dont know how to schedule it. – Sahil Jariwala Oct 15 '12 at 10:15
-
2@Stony — What should the OP have tried? Poking blindly at it with a stick? This isn't a particularly complex problem that you can have a go at and then get stuck on a particular bit. The question is clearly as "Where do you start with scheduling?" type question. You might be justified in pointing out a Google query that gets most of the answer, but "What you have tried?" isn't helpful. – Quentin Oct 15 '12 at 10:16
-
@Quentin : Well said. @ Sahil Jariwala : Refer cron jobs – Learner Oct 15 '12 at 10:22
-
@Boopa - Cron jobs will make my server busy as my database will have over 900000 + records. I am looking for daemon. – Sahil Jariwala Oct 15 '12 at 11:03
-
He's using Windows. Not Linux FYI. So it would be better for him to use Windows Task Scheduler. – EM-Creations Oct 29 '12 at 13:55
2 Answers
6
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.

EM-Creations
- 4,195
- 4
- 40
- 56
-
Thank you for your response. I would like to know futher in detail about setting up cron job as I am not getting satisfying results in google search – Sahil Jariwala Oct 15 '12 at 10:24
-
@SahilJariwala — You said Windows Task Schedular in a comment on my answer. Which are you using? Windows or *nix? – Quentin Oct 15 '12 at 10:25
-
@Quentin I am using Windows. I am newbie so I just selected the option as I am working in windows environment. – Sahil Jariwala Oct 15 '12 at 10:30
-
-
As Quentin is saying, are you currently developing this in Windows? If yes, when it's "live" is it going to be on a Linux server? If so, you'll need to use a cron job when it's on a live server and Windows Task Scheduler when developing (although I doubt you'll have a mail server configured on your computer) anyway; so it wouldn't send any emails anyway. – EM-Creations Oct 15 '12 at 10:31
-
@EM-Creations yes I am currently developing in Windows. Also when it is gonna be "live" it will hosted in windows machine. In the present senario, on my localhost my script is able to send emails. – Sahil Jariwala Oct 15 '12 at 10:35
-
Okay. So you'll need to create a Windows Task Scheduler Task to run that php file every 5 minutes. – EM-Creations Oct 29 '12 at 13:54
3
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.

Quentin
- 914,110
- 126
- 1,211
- 1,335
-
-
Yes, the manual for it. Or the Microsoft support site. e.g. [Windows Task Scheduler for XP](http://support.microsoft.com/kb/308569) – Quentin Oct 15 '12 at 10:25
-
The link has good explaination about windows task manager. But all that I am looking for is php code. – Sahil Jariwala Oct 15 '12 at 10:27
-
@SahilJariwala — You write the script that sends emails, then you use Task Schedular to run it every 5 minutes. – Quentin Oct 15 '12 at 10:28
-
yes I am done with script that sends email. But I am not getting on how to make task schedular invoke function in my codeigniter controller so that it sends emails as per the schedule – Sahil Jariwala Oct 15 '12 at 10:32
-
You aren't dealing with an HTTP request, the controller shouldn't be touched. You might make use of the model, but nothing else from the MVC application. Then just run the script itself. – Quentin Oct 15 '12 at 10:34
-
-
k. Besides I am also looking for php daemon to perform this job. – Sahil Jariwala Oct 15 '12 at 10:53