westman Posted May 27, 2012 Share Posted May 27, 2012 hi all, i need to include a php file that has only text in it into a $. i have this so fear... $email_message = '<html><body bgcolor="#FFFFFF">' . $name_of_the_sender . ' invites you to join them on the site.<br /><br />Thank you.include "../email.php"</body></html>'; my include "../email.php" is not working how do i get it working in this way? Link to comment Share on other sites More sharing options...
Guest So Called Posted May 27, 2012 Share Posted May 27, 2012 Not include. Rather, use file_get_contents(). Read the entire file into a PHP variable and then use that to populate your message. Link to comment Share on other sites More sharing options...
westman Posted May 28, 2012 Author Share Posted May 28, 2012 could you povide a demo script so i can understand better Link to comment Share on other sites More sharing options...
Guest So Called Posted May 28, 2012 Share Posted May 28, 2012 http://www.google.com/search?q=php+file_get_contents+example Link to comment Share on other sites More sharing options...
westman Posted May 28, 2012 Author Share Posted May 28, 2012 still not helpfull Link to comment Share on other sites More sharing options...
Guest So Called Posted May 28, 2012 Share Posted May 28, 2012 Seriously? $variable = file_get_contents('file_with_text_stuff.txt'); Put it in the same directory as your PHP script, or add path info. Then in your script you can just .= $variable, or use $variable in a double quoted character string. Or how about ...Thank you.' . $variable . '</body... (or put the included text wherever you want). Link to comment Share on other sites More sharing options...
Don E Posted May 28, 2012 Share Posted May 28, 2012 Here's basically what I think So Called is referring to and what I'm assuming you're trying to do: <?php$name_of_the_sender = 'John Doe'; // added this for obvious reasons $message = '<!doctype html><html><body bgcolor="#FFFFFF">'.$name_of_the_sender . ' invites you to join them on the site.<br /><br />Thank you';$message .= file_get_contents('sayhello.html'); // Don't think this will work with a php file because when echoing $message below, it outputs/includes everything even the php tags etc. If you look at the source file, you'll see php tags etc. sayhello.html only has <h4>hello world</h4> in it in this example.$message .= '</body></html>'; echo $message; // All the above even what's in sayhello.html is stored in $message.?> As for how you're going to do this with the email.php file though(using the above method, file_get_contents()), I'm not sure because of what's mentioned in the above comment. Link to comment Share on other sites More sharing options...
westman Posted May 28, 2012 Author Share Posted May 28, 2012 thank you it works Link to comment Share on other sites More sharing options...
westman Posted May 28, 2012 Author Share Posted May 28, 2012 how do i link a 3rd file in this way? for ex.index.php $message = file_get_contents('mail.php'); mail.php $message = file_get_contents('core_mail.html'); how would i code mail.php to include core_mail.html to show on index.php? Link to comment Share on other sites More sharing options...
birbal Posted May 28, 2012 Share Posted May 28, 2012 file_get_contents() wont execute the codes which it have. where include will execute it. when you use $message = file_get_contents('mail.php');it is just pulling the source code of mail.php rather than executing it. in other words...$message = file_get_contents('core_mail.html');this wont work. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 28, 2012 Share Posted May 28, 2012 You can use eval if you want to execute the code that file_get_contents returns. Make sure to read the notes in the manual. http://www.php.net/manual/en/function.eval.php Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now