Email Templates: Adding php includes

By depdesign - March 14, 2016

Is there a way to add php includes to the email templates?  I only see the Message HTML area via the cms.  Is there a template file that I can modify to add a permanent include?  

Dan Perez

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