schedule an email in 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.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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.

Solution 2

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.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply