cron job not calling php file

岁酱吖の 提交于 2019-12-13 19:14:11

问题


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.

I wrote cron job in the following way

#11 01 * * * /var/www/mail.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.";
?>

回答1:


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


来源:https://stackoverflow.com/questions/9460827/cron-job-not-calling-php-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!