summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes1
-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
-rw-r--r--config/mailer.jsonbin0 -> 316 bytes
6 files changed, 70 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes
index da046eb..20dfc9b 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,2 +1,3 @@
config/db.json filter=git-crypt diff=git-crypt
app/frontend/encryption.xml filter=git-crypt diff=git-crypt
+config/mailer.json filter=git-crypt diff=git-crypt
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>
diff --git a/config/mailer.json b/config/mailer.json
new file mode 100644
index 0000000..5de7be2
--- /dev/null
+++ b/config/mailer.json
Binary files differ