|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-12-14 15:49 UTC] cmb@php.net
-Status: Open
+Status: Not a bug
-Assigned To:
+Assigned To: cmb
[2020-12-14 15:49 UTC] cmb@php.net
[2020-12-14 21:29 UTC] folarin at engineer dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 15:00:02 2025 UTC |
Description: ------------ Hi all, I'm using the output buffer to render a php file, capturing the content and sending it via email. The process works fine for only one such cycle. That is only one file to read, and send as email to a user. I usually have to send emails to user(confirming their actions) and to admin(to act on user actions) on the same http user request. The issue with the above is that output buffer returns an empty string for the second email file content. As a check, I did each email sending operation in isolation and they both worked - showing there was no errors with the individual files. Output buffer successfully parses the first file, whatever that is, and returns the html string content. But on the second call to the method to parse using output buffer it returns an empty string. php --version PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies To the best of my knowledge, toggling each of the PHP_OUTPUT_HANDLER_CLEANABLE, etc options didn't help. Thanks Test script: --------------- public function getEmailBody(string $php_file_template_path){ ob_start(null,null,PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHABLE | PHP_OUTPUT_HANDLER_REMOVABLE); require_once($php_file_template_path); $xmail = ob_get_clean(); ob_end_clean(); return $xmail; } $msg = getEmailBody('path/to/file.php') mail("user@example.com","My subject",$msg); //this works for the above, but the following fails, that is $msg='', and so empty email content is reported: $msg2 = getEmailBody('path/to/another/file.php') mail("admin@example.com","My subject",$msg); Expected result: ---------------- That both user@example and admin@example get the appropriate emails. But in the above case, only user@example gets the email, the admin email returns an empty file read and hence empty email body