summaryrefslogtreecommitdiff
path: root/app/frontend
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-11-01 00:20:05 +0100
committeremkael <emkael@tlen.pl>2016-11-01 00:20:05 +0100
commiteb322a1a61237035718214ab4a1fce67c232262f (patch)
tree03df03233f86ae862e0c588617cb9f167cb04631 /app/frontend
parent6181693f1d4b021da8a699c19f5323a17ffab1de (diff)
* PHPMailer-based mailer module
Diffstat (limited to 'app/frontend')
-rw-r--r--app/frontend/mail/MailModule.php26
-rw-r--r--app/frontend/mail/Mailer.php41
l---------app/frontend/mail/config.json1
-rw-r--r--app/frontend/mail/config.xml1
4 files changed, 69 insertions, 0 deletions
diff --git a/app/frontend/mail/MailModule.php b/app/frontend/mail/MailModule.php
index 5f7749b..e10c556 100644
--- a/app/frontend/mail/MailModule.php
+++ b/app/frontend/mail/MailModule.php
@@ -1,16 +1,29 @@
<?php
Prado::using('System.I18N.Globalization');
+Prado::using('Application.mail.Mailer');
Prado::using('Application.mail.MailTemplate');
Prado::using('Application.mail.MailTemplateTranslator');
class MailModule extends TModule {
+ private $_configPath;
+ private $_config;
+
private $_templatePath;
private static $_templateExtension = 'html';
private $_templateCacheSubpath = 'mail';
private static $_templateTranslationCatalogue = 'messages';
+ public function setConfigPath($configPath) {
+ $this->_configPath = TPropertyValue::ensureString($configPath);
+ $this->_config = json_decode(
+ file_get_contents(
+ Prado::getPathOfNamespace($this->_configPath, '.json')
+ )
+ );
+ }
+
public function setTemplatePath($templatePath) {
$this->_templatePath = Prado::getPathOfNamespace(
TPropertyValue::ensureString($templatePath)
@@ -90,6 +103,19 @@ class MailModule extends TModule {
return $template;
}
+ public function getMailer() {
+ if (!$this->_config) {
+ throw new TConfigurationException(
+ Prado::localize(
+ 'Mailer not configured'
+ )
+ );
+ }
+ $mailer = new Mailer();
+ $mailer->configure($this->_config);
+ return $mailer;
+ }
+
}
?>
diff --git a/app/frontend/mail/Mailer.php b/app/frontend/mail/Mailer.php
new file mode 100644
index 0000000..327c9af
--- /dev/null
+++ b/app/frontend/mail/Mailer.php
@@ -0,0 +1,41 @@
+<?php
+
+Prado::using('Lib.phpmailer.PHPMailerAutoload');
+Prado::using('Application.mail.MailTemplate');
+
+class Mailer extends PHPMailer {
+
+ public function __construct() {
+ $this->isSMTP();
+ $this->SMTPAuth = TRUE;
+ }
+
+ public function configure($config) {
+ $this->Host = $config->smtp->host;
+ $this->Port = $config->smtp->port;
+ $this->Username = $config->smtp->user;
+ $this->Password = $config->smtp->pass;
+ if ($config->smtp->tls) {
+ $this->SMTPSecure = 'tls';
+ }
+ $this->setFrom($config->mail->from, $config->mail->name);
+ if ($config->mail->send_copies) {
+ $this->addBCC($config->mail->from);
+ }
+ }
+
+ public function sendTemplate(MailTemplate $template, $subject, $to, $name) {
+ $this->addAddress($to, $name);
+ $this->isHTML(TRUE);
+ $this->Subject = $subject;
+ $html = $template->execute();
+ $this->Body = $html;
+ $this->AltBody = strip_tags($html);
+ $result = $this->send();
+ $this->clearAddresses();
+ return $result;
+ }
+
+}
+
+?>
diff --git a/app/frontend/mail/config.json b/app/frontend/mail/config.json
new file mode 120000
index 0000000..cde12af
--- /dev/null
+++ b/app/frontend/mail/config.json
@@ -0,0 +1 @@
+../../../config/mailer.json \ No newline at end of file
diff --git a/app/frontend/mail/config.xml b/app/frontend/mail/config.xml
index d7d0e64..366e763 100644
--- a/app/frontend/mail/config.xml
+++ b/app/frontend/mail/config.xml
@@ -3,6 +3,7 @@
<modules>
<module id="mail"
class="Application.mail.MailModule"
+ ConfigPath="Application.mail.config"
TemplatePath="Application.mail.templates"
TranslationCatalogue="messages" />
</modules>