Extra email from Cron Daemon when running an email list script

纵然是瞬间 提交于 2020-01-17 04:10:21

问题


I have a PHP script that sends out a bi-weekly reminder to subscribers. Each time it sends out the email it also sends out an email that comes in from "Cron Daemon." When I first wrote the script, it didn't send this email, but now it does. I have a few questions about this.

This is what the email says:

Set-Cookie: PHPSESSID=((random letters and numbers here)); path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-type: text/html
  1. What does this email mean?
  2. Why is this email being sent?
  3. Is there a way to stop the scrip from sending this email?

回答1:


Cron reads the stdout/stderr of the command that gets executed, if something is written then cron sends an E-Mail.

I guess the php-executable is compiled as "cgi" or "fcgi" so it emits those headers by default.

To solve this you have apparently three possible solutions:

  • Use the "cli" version of PHP
  • Redirect stderr and stdout to /dev/null (that means append > /dev/null 2>&1 to your cron command).
  • Define MAILTO="" (see this page).



回答2:


My guess is your PHP script is rendering something to the output. If anything gets rendered at all, cron forwards that to the default administrator email.

There's two solutions to this:

1) Fix your PHP script to not output anything at all. This is sometimes harder than it would seem, especially for non-trivial scripts.

2) Prevent the cron script from ever having an output. The drawback to this method is you won't get a notice when the script fails, either. To stop the output, use something like this:

#Before
* * * * * php /path/to/script
#After
* * * * * php /path/to/script > /dev/null 2>&1


来源:https://stackoverflow.com/questions/6952082/extra-email-from-cron-daemon-when-running-an-email-list-script

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