0

I've got an HTML file I use as a template for a PHP email, and I want to just pull the contents of the HTML file and put it in a string, but my PHP content isn't showing.

My current html file can be seen at http://pastebin.com/iNgaHRky

I can get the file to be pulled, but the PHP parts in it aren't running. The email is just coming through as if I was previewing the file itself.

My Code:

ob_start();
include(site_url()."/emails/templates/new_user_admin.html");
$adminMessage = ob_get_clean();
ob_end_clean();

Can anyone let me know if what I'm trying to do is possible, and any way to get this to work?

I've also tried file_get_contents()

7
  • 2
    Why not just rename it to a .php and use include like the rest of us? Commented Sep 20, 2013 at 12:08
  • @Fluffeh because it's just a template file that I want to be able to preview when coding without needing a server environment. :). Commented Sep 20, 2013 at 12:10
  • @AlmaDoMundo No errors at all. The email comes through, just showing all the PHP tags though. Commented Sep 20, 2013 at 12:10
  • Not to be offensive, but it really boggles me that you can code on a "non-server environment". Surely you have a test machine set up to see how things work? how do you do thorough testing if you aren't seeing how it REALLY works? Commented Sep 20, 2013 at 12:12
  • could be that you need text/html in the email header, not sure exactly how but you can search Commented Sep 20, 2013 at 12:12

1 Answer 1

1

It just interprets the file as a pure string.

I really dont think you should be expecting the php parts to be working. they will just be text now. not php.

You could try using string replace on the string created once you have used file_get_contents() http://php.net/manual/en/function.str-replace.php

So, for example, you would put in the html file {{siteurl}} and use string replace to replace it with something like .site_url()."/emails/images/generic-header.jpg

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.