From eb322a1a61237035718214ab4a1fce67c232262f Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 1 Nov 2016 00:20:05 +0100 Subject: * PHPMailer-based mailer module --- app/frontend/mail/MailModule.php | 26 +++++++++++++++++++++++++ app/frontend/mail/Mailer.php | 41 ++++++++++++++++++++++++++++++++++++++++ app/frontend/mail/config.json | 1 + app/frontend/mail/config.xml | 1 + 4 files changed, 69 insertions(+) create mode 100644 app/frontend/mail/Mailer.php create mode 120000 app/frontend/mail/config.json (limited to 'app/frontend') 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 @@ _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 @@ +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 @@ -- cgit v1.2.3