EmailTemplate

Most of the emails sent from Ofuz are stored in a table called email_template and managed by an object call EmailTemplate.

We have a basic user interface to add/edit/delete emailtemplates in the script: adm_email_templates.php

EmailTemplate objects are used with one of the [OfuzObject:Emailer] object so send email messages.

Class

The Object it self doesn't send emails. To send emails with the EmailTemplate see Send Emails to Contacts), send_emails_to_ofuz_users or Emailer.

It simply manipulate Email Templates and store them in a Database.

The constructor accept the EmailTemplate name as a parameter, this will instantiate an EmailTemplate previously stored in the database table email_template.

<?php
    $do_template = new EmailTemplate("regthank");
?>

Will create the $do_template object with the EmailTemplate to thank new users on registration.

if you have multiple languages the constructor will use the global variable $_GLOBALS['cfg_lang'] to select the template in the proper language.

The EmailTemplate extends the DataObject so it inherit all the data manipulation methods.

Examples

Here are a couple of example of creating an EmailTemplate Object without storing it in the database.

The suggested syntax for custom email templates :

    $do_template = new EmailTemplate();
    $do_template->setFrom("phil@sqlfusion.com", "Philippe Lewicki")
                ->setSubject("This is an example")
                ->setMessage("This is the content of the sample message");

The detailed way:

  $do_template = new EmailTemplate();
  $do_template->setSenderEmail("philippe@sqlfusion.com"); 
  $do_template->setSenderName("Philippe Lewicki"); 
  $do_template->setSubject("This is an example");
  $do_template->setBodyText("This is the content of the sample message");
  $do_template->setBodyHtml(nl2br($do_template->bodytext));

You can use the $do_template object as is to send an Email message.

To store the template in the database for later use give it a name and use the add() method.

  $do_template->setTemplateName("my_example");
  $do_template->add();

When adding an email template leave the sender empty to have it dynamically set by method like Contact→sendMessage() or User→sendMessage()

Variables

table emailtemplate

+-----------------+--------------+------+-----+---------+----------------+
| Field           | Type         | Null | Key | Default | Extra          |
+-----------------+--------------+------+-----+---------+----------------+
| idemailtemplate | int(10)      | NO   | PRI | NULL    | auto_increment | 
| subject         | varchar(150) | NO   |     |         |                | 
| bodytext        | text         | NO   |     | NULL    |                | 
| bodyhtml        | text         | NO   |     | NULL    |                | 
| name            | varchar(254) | NO   |     |         |                | 
| sendername      | varchar(254) | NO   |     |         |                | 
| senderemail     | varchar(254) | NO   |     |         |                | 
| thumbnail       | varchar(70)  | NO   |     |         |                | 
| internal        | varchar(10)  | NO   |     |         |                | 
| language        | varchar(30)  | NO   |     | NULL    |                | 
+-----------------+--------------+------+-----+---------+----------------+
 
ofuzobject/email_template.txt · Last modified: 2010/08/26 15:06 by philippe
 
Copyright © SQLFusion LLC all rights reserved