3

I need to send emails hourly and daily. I've tried nearly everything but it appears my crontab just won't work. If I run the scripts via a browser e.g

http://localhost/Maisha/Functions/sendhourlymails.php  

my emails get sent beautifully.(I moved default website localhost to public_html.) I don't know whats wrong. I read some post in stack overflow including the executable path of php helps hence I've put the /usr/bin/php before the actual script to be cronned will work but it does not. Removing /usr/bin/php does not work. Adding php before the actual script isn't working. I have the following entries in my crontab.

# m h  dom mon dow   command
0  *  *   *   *    /usr/bin/php /home/maxwell/public_html/Maisha/Functions/sendhourlymails.php
0  0  *   *   *    /usr/bin/php /home/maxwell/public_html/Maisha/Functions/senddailymails.php
MaxI
  • 763
  • 2
  • 10
  • 43

3 Answers3

6

Try to call the script via http with wget like so:

* * * * * wget http://mysite.com/myscript >/dev/null 2>&1
markus
  • 38,729
  • 23
  • 95
  • 139
0

Yeh, wget is good option, also you can try to use:

0 * * * * /usr/sbin/php /usr/bin/php /home/maxwell/public_html/Maisha/Functions/sendhourlymails.php

but it could work wrong due to relative paths.

Also you should look at http://php.net/manual/en/features.commandline.php

Ivan
  • 1
0

Try to put this into your .php file

<?php
    #!/usr/local/bin/php -q
//your code here
?>

Then if you include any file into this file you must use something like:

include"/var/www/../your_absolute_path_from_root_folder/connect.php";

Finnaly make sure this file has the right permissions..Try

chmod 755 /var/www/.../file.php

Then if you edit your crontab file with the following command

vi /etc/crontab

put something like

10 6 * * * root php /var/www/..path../file.php

and restart the service with this command

/etc/init.d/cron restart

you have do your job!!

  • Note-Tip:the php file isn't neccessery to be into public_html folder!!
Chris P
  • 1,534
  • 1
  • 21
  • 44