theMaab Posted March 4, 2009 Share Posted March 4, 2009 I have an email I'm sending (using phpmailer class) and that is working fine. However, I have a php file I would like to include in the body of this email. The php file is used to display a nested table, but I can not get it to show in the email body correctly. The php file i'm tring to include has code like this: <table><tr><td><?php echo $size1; ?></td><td><?php echo $size2; ?></td></tr></table> Where I'm trying to use this looks like: $emailBody="This is the start of my email"; $emailBody.=include('myphpfile.php); // but need to parse the php in the file first (fill in the variables) $emailBody.="The end of my email"; I hope I explained it okay, I guess in short, I have a php file that echoes out values I use to display on a page. I would like to include that in my email body. Thanks a mil for any input, James Quote Link to comment https://forums.phpfreaks.com/topic/147970-include-php-file-for-my-email-body/ Share on other sites More sharing options...
RussellReal Posted March 4, 2009 Share Posted March 4, 2009 <?php ob_start(); include("myphpfile.php"); $content = ob_get_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/147970-include-php-file-for-my-email-body/#findComment-776625 Share on other sites More sharing options...
theMaab Posted March 4, 2009 Author Share Posted March 4, 2009 Awesome, this worked perfect!!! Thank you so much for your help. I was able to use those lines of code and it worked first try. I'm going right now to read up on ob_start();. My coded ended up looking like this, for those interested: <?php ob_start(); include("myphpfile.php"); $content = ob_get_flush(); $emailBody = "The start of my email body."; $emailBody .= $content; // this worked perfectly, parsed the PHP from the file, didn't have to mod anything $emailBody .= "The end of my email body."; ?> This question was SOLVED Quote Link to comment https://forums.phpfreaks.com/topic/147970-include-php-file-for-my-email-body/#findComment-776657 Share on other sites More sharing options...
theMaab Posted March 4, 2009 Author Share Posted March 4, 2009 I found a small issue using the method above. I found when I could call ob_get_flush() to set the contents from the file, it would also echo out that content right then on the screen. So it's no incorrect, could be used if that was needed. After doing some reading I found ob_get_clean(), and simply replaced the flush and it worked fine, just setting the $content var and not also echoing it to the screen. Final code is: <?php ob_start(); include("myphpfile.php"); $content = ob_get_clean(); $emailBody = "The start of my email body."; $emailBody .= $content; // this worked perfectly, parsed the PHP from the file, didn't have to mod anything $emailBody .= "The end of my email body."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/147970-include-php-file-for-my-email-body/#findComment-776720 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.