Email Templates: Adding php includes

By ross - March 16, 2016

Hi 

Thanks for posting.

You won't be able to put php includes into an email template.  That isn't the way either work.

What you can do instead is put the HTML from your include right into the HTML template.

Let me know if you'd like more detail.

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By depdesign - March 18, 2016

In case anyone else wants to do something similar I was able to find a solution. 

I needed to add a php header and footer using the Email Templates and was able to do with two custom placeholders.

I first added a header and footer  to the placeholder array:

 $emailHeaders = emailTemplate_loadFromDB(array(
          'template_id'  => 'USER-PASSWORD-RESET',
          'placeholders' => array(
          'header'  =>  file_get_contents('header.php',TRUE),
          'footer'  =>  file_get_contents('footer.php',TRUE),
          'user.username' => $user['username'],
            'user.email'    => $user['email'],
            'loginUrl'      => realUrl($GLOBALS['WEBSITE_LOGIN_LOGIN_FORM_URL']),
            'resetUrl'      => realUrl($GLOBALS['WEBSITE_LOGIN_RESET_URL'] . "?userNum={$user['num']}&resetCode=" . _generatePasswordResetCode( $user['num'] )),
        )));

Then in the email template I added #header# in the top of the Message HTML code and added #footer# at the bottom.

This setup was extremely helpful as I wanted to run db generated content in the email without having to copy and paste html code everytime I send an email.  It also helps clean your coding as having a header and footer include doesnt require that code in the Message HTML area.

Hope this helps! 

Dan Perez