I am running a script every night and the output of the script will only be send to a mail address. But the problem is that I need to receive a copy of the output in my own mailbox. I registered an shutdown handler in the script and I tried to send a mail with functions like ob_get_contents which actually shows data. But only the last thing I printed to the terminal.
cronMail('Cron', ob_get_contents());
The function called is just a simple function which adds the default receiver and sender and call the PHP Mail function.
The output in the mail is:
array()
While the terminal has te following output:
Starting cron...
Exiting...
array()
Can anyone tell me how to receive the whole output? I started the output buffer by using the ob_start method. And after each line I make sure there is an ob_flush method called so the output will also be send to the browser if the script is called directly.
ob_flushstands in your way, see the linked description on the manual page, it is pretty clear about that: It flushes the buffer so outputs it.You do not want that. Remove the calls to it and you should be fine.
This variant ensures that you get your own email but also the output is passed along to cron. This can be useful if you do some error reporting in the
cronMailfunction, so that at least there is some way to further debug that.Another alternative is to register an output handling function that stores the output on the go. But that is less trivial so I keep it out.