0

REF : PHP: Suppress output within a function?

Using the method suggested at the above link, i tried to suppress the output of mail function in PHPMAILER. But seems it suppresses the mail itself. What's the alternative to suppress the echos by mail library, so that a single echo $returnValue can be achieved ?

ob_start();
    include('mail.php');   //<< USING PHPMAILER 
ob_end_clean();

echo $returnValue
Community
  • 1
  • 1
Vishwas
  • 1,533
  • 2
  • 19
  • 40
  • it depends what mail.php is doing - if it is printing your mail to the screen then your OutputBuffer will catch it - that's what they do. Are you saying that $returnValue is something set inside your mail.php that isn't accessible in the parent scope? – kristopher Oct 04 '12 at 19:13
  • including phpmailer should not do *any* output. Your question makes not much sense I must admit. – hakre Oct 04 '12 at 19:15
  • it's echoing much output before $returnValue . It's not a normal mail function. It's a file from phpmailer library. – Vishwas Oct 05 '12 at 05:16

1 Answers1

1

ob_end_clean trashes whatever's been buffered. If you want to output what you've captured in the buffers, you need

$output = ob_get_clean();
echo $output;

That being said, output buffering will not affect sending an email, because that's done purely in the background and not subject to the buffering. the ob_*() buffering only captures output from the script, e.g. anything from echo/print calls. mail() itself does not use either of those to generate/send the mail.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • 1
    I got the impression that something in mail was Excepting to the screen and that's what he was trying to buffer - the exception – kristopher Oct 04 '12 at 19:21
  • @kristopher, Ya. Tht's what the problem is. It's echoing out mail result ( A lot of data that talks about mail header and other details). I want to suppress that. As it get's echoed before $returnValue, and creates problem in the application. – Vishwas Oct 05 '12 at 05:15
  • I don't know what mail.php does, what you have above should grab all output - but if you're outputting errors, well, you won't catch those separately. do you have a link to a git of the phpmailer script that I could take a look at? – kristopher Oct 05 '12 at 13:29