Email Templates - HTML Headers, etc

3 posts by 2 authors in: Forums > CMS Builder
Last Post: August 9, 2016   (RSS)

By gregThomas - August 5, 2016

Hey perchpole, 

CMS Builder injects it's own custom header and footer when the message is sent. But you can pass a variable into the emailTemplate_loadFromDB function and pass in your own custom headers and footers instead. Here is an example that would make all the text in the email red:

  $emailHeaders = emailTemplate_loadFromDB(array(
    'template_id'        => 'USER-SIGNUP',
    'addHeaderAndFooter' => false,
    'placeholders'       => array(
      'user.username'     => "enter value",
      ''        => "enter value",
      'user.password'     => "enter value",
      'loginUrl'          => "enter value",

    //Get the subject to use in the title tag.
    $htmlTitle  = htmlencode($emailHeaders['subject']);
    //Custom Header
    $header = <<<__HTML__
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style type="text/css">
  p { margin-bottom: 1em; color:red; }

// ***NOTE*** style tag is for Yahoo Mail which otherwise drops paragraph spacing -
// ... having a defined <title></title> helps get by spam filters

  //Generate the footer
  $footer = <<<__HTML__
  //Add teh footer and header to the email headers.
  $emailHeaders['html'] = $header . $emailHeaders['html'] . $footer;

  //Send the email
  $mailErrors = sendMessage($emailHeaders);
  if ($mailErrors) { die("Mail Error: $mailErrors"); }

This is example code, so you might have to make a few changes to get it working. 

I've added the addHeaderAndFooter to emailTemplate_loadFromDB so that function won't add it's own headers and footers. Then after the function has been called I'm adding in my own custom header and footer. 



Greg Thomas

PHP Programmer -

By Perchpole - August 9, 2016

Thanks, Greg -

The code is perfect. It works brilliantly!