Menu

Example

Mario Trojan

Example Page

HTML Template

<!-- All "mailvar"- and "mailval"-elements in this document will be replaced -->
<mail>
    <!-- Subject and mail headers can be set here. 
        Variables can also be used to fill headers! -->
    <mailfields>
        <subject>New Order: <mailvar key="OrderNumber" /></subject>
        <to><mailvar key="Receiver" /></to>
        <cc><mailvar key="Receiver" /></cc>
    </mailfields>
    <mailbody>
        <!-- put html mail contents here -->
        <html>
            <head>
                <style type="text/css">
                    body {
                        font-family: Verdana;
                        color: #0000AA;
                    }

                    div#clickme {
                        color: #FFFFFF;
                        background-color: #0000AA;
                    }
                </style>

                <!-- this works only if javascript is allowed in receiver's mail client -->
                <script type="text/javascript">
                    function ShowHide () {
                        var element = document.getElementById('ShowHide');
                        if (element.style.display == 'none') {
                            element.style.display = 'block';
                        }
                        else {
                            element.style.display = 'none';
                        }
                    }
                </script>
            </head>
            <body>
                <!-- example for a simple string -->
                <h1><mailvar key="Headline1" /></h1>
                <p>This Mail belongs to Order <mailvar key="OrderNumber" /></p>
                <div id="clickme" onclick="ShowHide();">
                    Click Me!
                </div>
                <div id="ShowHide">
                    This div will be hidden if mail client allows javascript
                </div>

                <p>
                    The following documents belong to this order:
                </p>
                <table>
                    <tr><th>Document number</th><th>Document title</th></tr>
                    <!-- example for a html table filled from an associative array -->
                    <mailvar key="Documents" type="array" >
                        <tr><td><mailval index="DocumentNumber" /></td><td><mailval index="DocumentTitle" /></td></tr>
                    </mailvar>
                </table>
            </body>
        </html>
    </mailbody>
</mail>

PHP Usage

<?php

    // Common PHP settings
    date_default_timezone_set('Europe/Berlin');

    ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 1);

    $mail_address = 'john@doe.org';
    ini_set('sendmail_from', $mail_address);


    // Require our libs
    require_once('../../phmte.php');

    // Init a new Template object with a path to the template
    $tpl_path   = 'template.html';
    $tpl        = new HTMLMailTemplate($tpl_path);

    // Generate a new TemplateInformation object, where the Variables will be stored
    // Several additional engine settings can also be set here, like charset and content-type of the mail, or tagnames inside the template file.
    $params     = new HTMLMailTemplateInformation();
    $params->vars = array(  'OrderNumber' => 'TST0012345',
                            'Headline1' => 'The Order has been generated',
                            'Receiver' => $mail_address,
                            'Documents' => array(
                                                array('DocumentTitle' => 'Document 1', 'DocumentNumber' => '1234567890'),
                                                array('DocumentTitle' => 'Document 2', 'DocumentNumber' => '0987654321')
                                            )
                        );

    // Tell the engine to fill the template with these params
    $tpl->FillTemplate($params);

    // Get the prepared mail and send it
    $mail = $tpl->GetMail();
    #print nl2br(print_r($mail,true));
    $mail->Send();

    print "Mail successfully sent.";

?>

Related

Wiki: Home

Auth0 Logo