How to send Email on (repeating) time intervals in php

the mail() function

Moderators: macek, egami, gesf

riaz123
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Jul 18, 2011 4:31 am

How to send Email on (repeating) time intervals in php

Postby riaz123 » Mon Aug 08, 2011 2:57 am

Actually my requirement is that, I have to send email after some (pre-defined) time interval (which is set by Admin through admin panel etc) like "After every week" or "every fortnight" or "every month" or "daily".

I have inserted all data i.e users email info etc and the time interval after which email notification is to be sent in Database.

Now I am required to run a script in cron job to send email notifications to users with their respective (repeating) time interval (set by admin and stored in DB). I am confused how to do so.
So can anyone kindly help me out to resolve this problem. Thanks in advance.

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: How to send Email on (repeating) time intervals in php

Postby egami » Mon Aug 08, 2011 5:40 am

php by itself can't do any cron jobs..
but you can set the cron to run a php script as little as every minute of the day.

For more information on cron jobs, do a google search.

your PHP script would have something to the effect of..

1. The current time
2. Search for all queries to run at current time with in a few seconds of 'the current time'
3. run your email routines against those queries that return.

rytec
New php-forum User
New php-forum User
Posts: 5
Joined: Thu Sep 22, 2011 5:24 am

Re: How to send Email on (repeating) time intervals in php

Postby rytec » Thu Sep 22, 2011 6:02 am

To make a php script for example in Linuxserver, doe sit need to have the php extension? or would this be a totaly normal script in linux which also can do a query to the mysql dbase?
which way is better?

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: How to send Email on (repeating) time intervals in php

Postby egami » Thu Sep 22, 2011 7:22 am

you would run it as root, but you call php application, and then the file..


example:

/5 * * * * root php /var/www/html/dome.php


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest