Search code examples
phpflush

PHP flush function causing weird characters on the screen


After so much trouble I find out that when I use the flush function in my PHP mail script then I get garbage or dump characters on browser like below.

alt text

The code is below

if ($mail->Send()) {
    echo "<br><font color=darkgreen>[$num successful send to $to]</font> ";
    // flush();
    return true;
}

If I comment that flush line then out is simple English but I uncomment that the whole page the text looks like garbage.

Now is that a PHP problem, browser problem or server problem?

If I use the same script from the shell, I mean execute inside the shell terminal then I can see the HTML output. But it does not work in browsers.


Solution

  • I found the answer to my own question. I had to turn

    zlib_compression off
    

    in my php.ini settings file.

    (What does that mean and why did it work?. I had been trying this for 1 year but could not resolve the problem but now it worked.)