peace_love
peace_love

Reputation: 6461

How can I run a php file via cronjob?

I want to send an automatic email via cronjob.

I made a file with the name send_email.php. If I open it in the browser the email is sucessfully sent. But when I want to open the file via cronjob I get some error messages:

   /is/htdocs/user/.../myfolder/send_email.php: line 1: ?php: No such file or directory
   /is/htdocs/user/.../myfolder/send_email.php: line 3: syntax error near unexpected token `'includes/config.php''
   /is/htdocs/user/.../myfolder/send_email.php: line 3: `require('includes/config.php'); '

My first 3 line in send_email.php are:

<?php 

require('includes/config.php'); 

Why is this not working?

Upvotes: 1

Views: 74

Answers (2)

Bart
Bart

Reputation: 1268

Wrong require path probably. You need to check where is send_email.php located relatively to cron working directory. Or you may use lynx for that

* * * * * lynx -dump http://domain.tld/send_email.php

Upvotes: 0

Franz Gleichmann
Franz Gleichmann

Reputation: 3568

judging from the first error message, you are probably trying to execute your php-scripts as shell-scripts. try executing the php-binary instead

/usr/bin/php /path/to/your/cron.php

Upvotes: 3

Related Questions