Quick Start
Composer:
"phpmailer/phpmailer": "^6.5"
git clone [email protected]:FestiPlugins/PHP_Festi_Plugin_Mail.git plugins/Mail
CREATE TABLE `email_logs` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`ident` varchar(64) NOT NULL,
`emails` varchar(255) DEFAULT NULL,
`subject` text NOT NULL,
`body` longtext NOT NULL,
`files` text,
`cdate` date NOT NULL,
`ctime` datetime NOT NULL,
`is_sended` tinyint(4) DEFAULT '1',
`error` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `email_templates` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ident` varchar(64) NOT NULL,
`caption` varchar(255) NOT NULL,
`subject` text NOT NULL,
`body` text NOT NULL,
`title` varchar(255) NULL DEFAULT NULL,
`template` varchar(128) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ident` (`ident`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `festi_settings` (`id`, `caption`, `name`, `value`) VALUES (NULL, '', 'email_sender_from', '[DEFAULT_EMAIL]');
INSERT INTO `festi_settings` (`id`, `caption`, `name`, `value`) VALUES (NULL, '', 'email_sender_name', '[DEFAULT_FROM]');
config.php
define('MAIL_CACHE_PATH', '[PATH]');
// OR
$GLOBALS['config']['paths'] = array(
'cache' => FS_ROOT.'cache'.DIRECTORY_SEPARATOR
);
// Use SMTP
$GLOBALS['config']['smtp'] = array(
'from' => 'XXX',
'host' => 'ssl://XXXX',
'port' => '465',
'auth' => true,
'username' => 'XXXX',
'password' => 'XXXX'
);
INSERT INTO `email_templates` (`id`, `ident`, `caption`, `subject`, `body`, `title`, `template`) VALUES
(NULL, '[EMAIL_IDENT]', 'Test', 'TEST <?php echo $subject; ?>', '<html>\r\n<body>\r\nTEST <?php echo $userValuesObject->getFullName(); ?>\r\n</body>\r\n</html>', NULL, NULL);
$emailData = array(
'userValuesObject' => $userValuesObject,
'subject' => 'Test Subkect'
);
$this->plugin->mail->send(
'[EMAIL]',
'[EMAIL_IDENT]',
$emailData
);
mkdir plugins/Mail/templates/
vim plugins/Mail/templates/[TEMPLATE_NAME].phtml
user.phtml:
<html>
<body>
<p>Hi there,</p>
<?php echo $mailBody;?>
<br><br>
Best regards, <br>
<?php echo $data['userValuesObject']->getFullname(); ?>
</body>
</html>
UPDATE `email_templates` SET tempalte='[TEMPLATE_NAME]', `body` = ' TEST <?php echo $userValuesObject->getFullName(); ?> ' WHERE `ident` = '[EMAIL_IDENT]';
$emailData = array(
'mail_from' => $fromEmail,
'mail_from_name' => $fromName,
'charset' => $charset,
'replay_email' => $replayTo,
'replay_name' => $replayName
);
$this->plugin->mail->setDisplayRecipients(true);
Email Templates DGS
INSERT INTO `festi_sections` (`caption`, `ident`, `mask`)
VALUES ('Manage Email Templates', 'manage_email_templates', '6');
SET @id_section_manage_email_templates = (SELECT `id`
FROM `festi_sections`
WHERE `ident` = 'manage_email_templates');
SET @id_user_type_admin = (SELECT `id`
FROM `users_types`
WHERE `ident` = 'admin');
INSERT INTO `festi_sections_user_types_permission` (`id_section`, `id_user_type`, `value`)
VALUES (@id_section_manage_email_templates, @id_user_type_admin, '6');
After that, you'll be able to manage email templates in DGS by link /festi/email_templates/Mail/
.
Add menu item and user friendly url
SET @id_section_manage_email_templates = (SELECT `id`
FROM `festi_sections`
WHERE `ident` = 'manage_email_templates');
-- Add Mail plugin
INSERT INTO `festi_plugins` (`status`, `ident`)
VALUES ('active', 'Mail');
-- Add link for manage email templates page
INSERT INTO `festi_section_actions` (`id_section`, `plugin`, `method`, `mask`, `comment`) VALUES
(@id_section_manage_email_templates, 'Mail', 'onDisplayTemplates', '6', '');
INSERT INTO `festi_url_rules` (`plugin`, `pattern`, `method`)
VALUES ('Mail', '~^/manage/email/templates/$~', 'onDisplayTemplates');
SET @id_url_rule = (SELECT `id`
FROM `festi_url_rules`
WHERE `plugin` = 'Mail'
AND `method` = 'onDisplayTemplates');
INSERT INTO `festi_url_rules2areas` (`id_url_rule`, `area`)
VALUES (@id_url_rule, 'backend');
-- Add menu item
INSERT INTO `festi_menus` (`caption`, `url`, `id_parent`, `order_n`, `description`, `id_section`, `area`, `ident`)
VALUES ('Email Templates', '/manage/email/templates/', NULL, 30, NULL, @id_section_manage_email_templates, NULL, NULL);