Notification icon indicating copy to clipboard operation
Notification copied to clipboard

Email templates

Open jnorell opened this issue 6 years ago • 2 comments

It would be nice to have some simple email template support, to include some reusable blocks of css and html to make messages consistent across multiple notification definitions.

jnorell avatar Nov 01 '19 19:11 jnorell

Possibly useful for others, or as a basis for how/where to insert custom css into the message:

/**
 * Notification: add css to html head on outgoing messages.
 */
add_filter( 'notification/carrier/email/message', function( $message, $carrier, $trigger ) {

        // read .css file or whatever
        $css = "body { background-color: red; }";

        $html_mime = true;
        if ( function_exists( 'notification_get_setting' ) ) {
                $html_mime = notification_get_setting( 'notifications/email/type' ) === 'html';
        }
        $html_mime = apply_filters( 'notification/carrier/email/use_html_mime', $html_mime, $carrier, $trigger );

        if ( ! $html_mime ) {
                return $message;
        }

        if ( stripos( $message, '<html>' ) !== false ) {
                if ( stripos( $message, '</head>' ) !== false ) {

                        $message = preg_replace( "{</head>}i", "<style>{$css}</style></head>", $message, 1 );

                } // else malformed html ?

        } else {

                $message = <<<HTML
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <style> {$css} </style>
</head>
<body>
        {$message}
</body>
</html>
HTML;
                
        }

        return $message;
}, 10, 3);

jnorell avatar Nov 09 '19 00:11 jnorell

The email templates is a high demand extension we plan to release: https://bracketspace.com/downloads/notification-email-templates/

jakubmikita avatar Jan 13 '20 13:01 jakubmikita