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:


  // USER-SIGNUP
  $emailHeaders = emailTemplate_loadFromDB(array(
    'template_id'        => 'USER-SIGNUP',
    'addHeaderAndFooter' => false,
    'placeholders'       => array(
      'user.username'     => "enter value",
      'user.email'        => "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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>$htmlTitle</title>
</head>
<body>

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


__HTML__;
// ***NOTE*** style tag is for Yahoo Mail which otherwise drops paragraph spacing - http://www.email-standards.org/blog/entry/yahoo-drops-paragraph-spacing/
// ... having a defined <title></title> helps get by spam filters

  //Generate the footer
  $footer = <<<__HTML__
</body>
</html>
__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. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Perchpole - August 9, 2016

Thanks, Greg -

The code is perfect. It works brilliantly!

:0)

Perch