\CGExtensions\EmailFileEmailStorage

This class can load and save email objects to the filesystem in a specialized format.

It will also search in the module directory, and in the /asssets/emails directory for emails.

Summary

Methods
Properties
Constants
__construct()
load()
save()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__construct()

__construct(\CGExtensions  $mod) 

Constructor

Parameters

\CGExtensions $mod

A reference to a module derived from CGExtensions.

load()

load(string  $name) : \CGExtensions\Email\Email|null

Load an email object from a file.

This method will look for a file with the specified name, ending with '.eml' in the following directories: assets/module_custom//emails, assets/emails, and modules//emails

It is expected that the file if exists, is a formatted text file with three sections:

top section (ini format) ==== ==== smarty template for email subject ==== ==== smarty template for email body

Parameters

string $name

the object name

Returns

\CGExtensions\Email\Email|null

Examples

<?php
/**
 * An example function demonstrating how to process and send a templated email from a module action.
 * Assuming that this is a module action file, in a module derived from CGExtensions
 * and a file entitled emails/foo.eml exists in the module directory.
 *
 * The foo.eml is a formatted text file that looks something line:
 *
 * encode_subject=true
 * ==== subject template ====
 * Notification from {sitename}
 * ==== body template ===
 * <h2>Hello {$my_name}</h3>
 * <p>This message was sent to you at <strong>{$smarty.now|date_format:'%x %X'}</strong></p>
 *
 * The top section of the file (above the section header separator) is in .ini file format
 * and allows specifying numerous options, and addresses
 * The second section of the file is a smarty template for the email subject.  Note that a subject cannot normally contain extended characters, and must be only one line long, unless encoded.
 * The third section of the eml file is a smarty template for the email body.  It permits HTML emails, but remember that stylesheets do not work.
 */
if( !isset($gCms) ) exit;

$email = $this->get_email_storage()->load('foo.eml');
if( $email ) {
    $email->add_data('my_name','foo bar');
    $email->add_address('somebody@localhost.localdomain');
    $this->create_new_mailprocessor($email)->send();
}

save()

save(\CGExtensions\Email\Email  $eml) 

Save an email object to a file.

Will ONLY save email files to the /assets/emails directory.

Parameters

\CGExtensions\Email\Email $eml

The object to save.