cron作业未调用php文件 [英] cron job not calling php file
问题描述
我正在尝试执行cron工作以调用php文件发送邮件。我尝试了很多时间,但是我没有成功。我没有发现问题可以有人帮助我。
I am trying to do cron job to call a php file to send mail.I tried lot of time but i am unsuccessful.I did not figured out the problem can some one please help me.
我以以下方式编写了cron作业
I wrote cron job in the following way
#11 01 * * * /var/www/mail.php
这是我所说的php字段
This is my php fiel what i am calling
<?php
#!/usr/bin/php
$to = "xxxx@xxx.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
推荐答案
要能够运行命令行中的php
脚本(没有明确告诉它应该与php一起运行),您需要确保它具有可执行位并且具有#!/ usr / bin / php
作为文件的第一行。在您的情况下,最好在以下位置添加 / usr / bin / php
(或您的 php
所在的位置) crontab
To be able to run php
scripts in a command line (without telling explicitly it should be run with php) you'll need to ensure it have executable bit set and have #!/usr/bin/php
as the first line in file. In your case it's probably better to add /usr/bin/php
(or wherever your php
is located) in from of your script name in crontab
:
11 01 * * * /usr/bin/php /var/www/mail.php
这篇关于cron作业未调用php文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!