如何通过cronjob运行php文件?

时间:2016-01-28 08:35:36

标签: php cron

我想通过cronjob发送自动电子邮件。

我创建了一个名为send_email.php的文件。如果我在浏览器中打开它,则会成功发送电子邮件。但是当我想通过cronjob打开文件时,我收到一些错误消息:

   /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'); '

send_email.php中我的第3行是:

<?php 

require('includes/config.php'); 

为什么这不起作用?

2 个答案:

答案 0 :(得分:3)

从第一条错误消息判断,您可能正在尝试将php脚本作为shell脚本执行。 尝试执行php-binary而不是

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

答案 1 :(得分:0)

错误的要求路径可能。您需要检查send_email.php相对于cron工作目录的位置。或者你可以使用lynx

* * * * * lynx -dump http://domain.tld/send_email.php
相关问题