raji20 Posted October 25, 2006 Share Posted October 25, 2006 I want to make the script to run automatically everyday that checks for the new emails, if any new mails are there, it need to forward to the specified address. I need this to be done via CRON JOB, how to do this, any help will be greatly appreciable. Quote Link to comment Share on other sites More sharing options...
xsist10 Posted October 25, 2006 Share Posted October 25, 2006 Firstly you'll need a script that checks the POP server for new mail and sends it to the new email address:Documentation: [url=http://www.php.net/imap]http://www.php.net/imap[/url]This is just some example code for imap:[code]<?php// This gets the first email in the mailbox$mailbox = imap_open("{localhost/pop3:110}INBOX", "#username#","#password#");$check = imap_check($mailbox);$new_messages = ($check->Recent ? true : false);$index=1;$header = imap_header($mailbox, $index);print("<PRE>");print("Header Date : " . $header->Date . "<BR>");print("Header To : " . $header->to) . "<BR>";print("Header From : " . $header->From . "<BR>");print("Header cc : " . $header->cc . "<BR>");print("Header ReplyTo : " . $header->ReplyTo . "<BR>");print("Header Subject : " . $header->Subject . "<BR></PRE>");print("<PRE>");print(imap_body($mailbox,$index));print("</PRE><HR>");imap_close($mailbox);?>[/code]Then add this line to your cronjob:0 12 * 10 1-7 /user/bin/php -f /location/of/scripts/to/execute.php[url=http://www.adminschoice.com/docs/crontab.htm]http://www.adminschoice.com/docs/crontab.htm[/url] Quote Link to comment Share on other sites More sharing options...
raji20 Posted October 25, 2006 Author Share Posted October 25, 2006 First Thanks a lot for your assistance, when i try to excute this comand from the linux server, 0 12 * 10 1-7 /usr/local/lib/php -f /www/htdocs/phpdocs/test/cron.phpit pops up the error saying-bash: 0: command not foundIs it correct what i have done or please guide me how to add this line to CRONJOB, Im very new to this topic. Quote Link to comment Share on other sites More sharing options...
xsist10 Posted October 25, 2006 Share Posted October 25, 2006 Sorry.. my bad for not being clear.You need to add this entry:[code]0 12 * 10 1-7 /usr/local/lib/php -f /www/htdocs/phpdocs/test/cron.php[/code]into /etc/crontab Quote Link to comment Share on other sites More sharing options...
raji20 Posted October 25, 2006 Author Share Posted October 25, 2006 thanks again for your assistance, when i tried this following command from the linux server[root@place etc]# crontab 0 12 * 10 1-7 /usr/local/lib/php -f /www/htdocs/phpdocs/test/cron.phpit shows me error saying crontab: invalid option -- fcrontab: usage error: unrecognized optionCan you please tell me about what i have did is correct or not, if it is wrong what i need to do, if it is correct how to correct this error. Quote Link to comment Share on other sites More sharing options...
xsist10 Posted October 25, 2006 Share Posted October 25, 2006 [quote author=raji20 link=topic=112636.msg457272#msg457272 date=1161769833][root@place etc]# crontab 0 12 * 10 1-7 /usr/local/lib/php -f /www/htdocs/phpdocs/test/cron.php[/quote]What you need to do is [u]edit[/u] /etc/crontab/etc/crontab is a text file which has a collection of commands in it to execute at specific times.So open /etc/crontab up with a text editor like so:[code]vi /etc/crontab[/code]And then add this to the bottom of the file[code]0 12 * 10 1-7 /usr/local/lib/php -f /www/htdocs/phpdocs/test/cron.php[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.