PHP to send weekly emails?

lozina

Lifer
Sep 10, 2001
11,711
8
81
I am wondering is it at all possible to have my php application automatically send emails every week?

well, the functionality I need is to be able to schedule a task to be run every week, and for this task to be administrable via the website.

anything in php to do this?

I know I could use a cron job I suppose, but then the user would not be able to administer it from my web applciation...
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
Why can't you write a PHP interface that interacts with cron? Or have the user-facing PHP script store information in a database, and have cron call your own PHP script that reads that information out and sends e-mails based on it.
 

lozina

Lifer
Sep 10, 2001
11,711
8
81
Why can't you write a PHP interface that interacts with cron? Or have the user-facing PHP script store information in a database, and have cron call your own PHP script that reads that information out and sends e-mails based on it.

dont know anything about php interfacing with cron - do you know any articles/examples off the top of your head I could take a look at?

thanks
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
1. Type crontab -e to edit your cron tab. Google 'crontab' if you don't know cron's syntax.

To run something every day, five minutes after midnight:
Code:
MAILTO=""
05 00 * * * /path/to/my/command.sh

2. Set up your command.sh to:
Code:
cat /path/to/email/msg.txt | mail -s "Subject" recipient@a.com -- -F"SenderName"

Happy cron-mailing.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
You could just have one nightly cron job that kicks off a php script, and the php script would look in the database for jobs that need to be run. Then, you could add as many jobs in your database as you want and the single cron job would run them all.
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
PHP (like most/all programming languages) can send commands to the system using the system() function:

http://php.net/manual/en/function.system.php

You can use that to interact with cron directly from PHP. Using the second method I described wouldn't require you to call cron using PHP at all.