Skip to content

Commit

Permalink
Issue #4919 - Add support for quick custom email template without sep…
Browse files Browse the repository at this point in the history
…arate file.
  • Loading branch information
CaMer0n committed Oct 27, 2023
1 parent 552af19 commit c419d40
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
11 changes: 9 additions & 2 deletions e107_handlers/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -913,9 +913,16 @@ public function arraySet($eml)
{
require_once(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_users.php"); // do not use e107::lan etc.

if(is_array($eml['template']) && !empty($eml['template']['plugin']) && !empty($eml['template']['name']) && !empty($eml['template']['key']))
if(is_array($eml['template']))
{
$tmpl = e107::getTemplate($eml['template']['plugin'],$eml['template']['name'], $eml['template']['key']);
if(!empty($eml['template']['plugin']) && !empty($eml['template']['name']) && !empty($eml['template']['key'])) // Plugin template
{
$tmpl = e107::getTemplate($eml['template']['plugin'],$eml['template']['name'], $eml['template']['key']);
}
elseif(isset($eml['template']['header']) && isset($eml['template']['body']) && isset($eml['template']['footer'])) // Custom Template
{
$tmpl = $eml['template'];
}
}
else
{
Expand Down
37 changes: 37 additions & 0 deletions e107_tests/tests/unit/e107EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,41 @@ public function testArraySet()
$this->assertStringNotContainsString('{MEDIA1}', $this->eml->Body);
}

/**
* Test using a custom template passed directly.
* @return void
*/
public function testArraySetInlineTemplate()
{
$eml = array(
'subject' => "[CUSTOM TEMPLATE EXAMPLE]",
'sender_email' => "[email protected]",
'sender_name' => "Test Person",
'replyto' => "",
'html' => true,
'priority' => 1,
'template' => ['subject'=>'{SUBJECT}', 'header'=>'<html lang="en"><body>', 'body'=>'<div><span>{NAME}</span> <small>{DATE}</small></div><div>{BODY}</div>', 'footer'=>'</body></html>'],
'body' => "This is the body text",
'cc' => '',
'shortcodes' => [
'NAME' => "TestName",
'DATE' => 'Jan 1st, 2020'
],
);

$this->eml->arraySet($eml);

$this->assertStringContainsString("[email protected]", $this->eml->From);
$this->assertStringContainsString("Test Person", $this->eml->FromName);
$this->assertStringContainsString("[CUSTOM TEMPLATE EXAMPLE]", $this->eml->Subject);

$this->assertStringContainsString('<html lang="en"><body>', $this->eml->Body);

$this->assertStringContainsString('<div><span>TestName</span> <small>Jan 1st, 2020</small></div><div>This is the body text</div>', $this->eml->Body);
$this->assertStringNotContainsString('{MEDIA1}', $this->eml->Body);
}


/**
* Test using an email template from e107_plugins/_blank/templates/_blank_template.php
* @return void
Expand Down Expand Up @@ -103,6 +138,8 @@ public function testArraySetPluginTemplate()
}




public function testArraySetNotifyTemplate()
{
$eml = array(
Expand Down

0 comments on commit c419d40

Please sign in to comment.