问题
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