简体   繁体   English

我的php脚本在由cron作业调用时未发送电子邮件

[英]My php script is not sending an email when called by a cron job

I am running a cron job every five minutes which calls a php script to check to see if users have imported any files for processing. 我每五分钟运行一次cron作业,它调用php脚本以检查用户是否已导入任何文件进行处理。

When I run the php script by going to the address in my web browser it runs the script and then sends the user a notification by email. 当我通过转到Web浏览器中的地址来运行php脚本时,它将运行该脚本,然后通过电子邮件向用户发送通知。 When I run the script using the cron job, the script works fine, but it doesn't send the user an email. 当我使用cron作业运行脚本时,脚本可以正常工作,但不会向用户发送电子邮件。 Any thoughts about why no email is sent? 关于为何不发送电子邮件的任何想法?

I'm running Ubuntu Hardy LTS. 我正在运行Ubuntu Hardy LTS。 The cron job is: Cron工作是:

*/5 * * * * /usr/bin/wget -–delete-after http://www.mywebsite.com/import_processing.php >/dev/null 2>&1

I'm using delete-after so that I don't get copies of the script piling up in my server directory. 我使用的是after-after,以便不会在服务器目录中堆积脚本的副本。 I'm suppressing output and errors also as I don't need email confirmation myself. 我也抑制了输出和错误,因为我自己不需要电子邮件确认。

The script uses the basic mail function, and as I said, works just fine when run from my browser. 该脚本使用基本的邮件功能,正如我所说,从我的浏览器运行时,该脚本可以正常工作。

Update: It looks like the issue is my php script is looking for a browser cookie to send the email. 更新:看来问题出在我的php脚本正在寻找浏览器cookie以发送电子邮件。 I imagine I'll have to find another way to get the user's identity. 我想我将不得不寻找另一种获取用户身份的方法。

run it like this 像这样运行它

*/5 * * * * /usr/bin/php /var/www/htdocs/blah/blah/import_processing.php >/dev/null 2>&1

when you use wget you are downloading the file, with php you are running the file, test your script running 当您使用wget来下载文件时,使用php运行文件,请测试脚本的运行情况

/usr/bin/php /var/www/htdocs/blah/blah/import_processing.php >/dev/null 2>&1

using the local path, just in case run 使用本地路径,以防万一运行

$ which php 

to figure out where it is installed 弄清楚它的安装位置

The script was running properly using wget or php; 使用wget或php脚本运行正常; the problem was that the php script looked for a browser cookie which didn't exist when the page was run outside of a web browser. 问题是当网页在Web浏览器之外运行时,php脚本查找的浏览器cookie不存在。

I changed the php script to do a database lookup instead and it worked just fine. 我更改了php脚本来进行数据库查找,并且工作正常。 Thanks for your suggestions. 谢谢你的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM