Jump to content

Include php file for my email body


theMaab

Recommended Posts

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.