Commit 135d3b55 authored by Tino Goratsch's avatar Tino Goratsch

- added some kind of default styling to the HTML e-mails

- send HTML e-mails via the contact form
parent c116dc72
......@@ -25,7 +25,7 @@ class SendEmail
/**
* Generates and sends an E-mail
*
* @param string $recipientName
* @param string|Core\Mailer\MailerMessage $recipientName
* @param string $recipientEmail
* @param string $from
* @param string $subject
......@@ -33,9 +33,23 @@ class SendEmail
* @param string $mailSignature
*
* @return bool
* @deprecated since version 4.8.0, to be removed with version 5.0.0. Use the 'core.mailer' service directly instead
*/
public function execute($recipientName, $recipientEmail, $from, $subject, $body, $mailSignature = '')
{
public function execute(
$recipientName,
$recipientEmail = '',
$from = '',
$subject = '',
$body = '',
$mailSignature = ''
) {
if ($recipientName instanceof Core\Mailer\MailerMessage) {
return $this->mailer
->reset()
->setData($recipientName)
->send();
}
if (!empty($recipientName)) {
$to = [
'name' => $recipientName,
......
......@@ -3,6 +3,7 @@
namespace ACP3\Core;
use ACP3\Core\Helpers\StringFormatter;
use ACP3\Core\Mailer\MailerMessage;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Installer\Schema;
use InlineStyle\InlineStyle;
......@@ -97,6 +98,7 @@ class Mailer
* @param string|array $from
*
* @return $this
* @deprecated since version 4.8.0, to be removed with version 5.0.0
*/
public function setFrom($from)
{
......@@ -109,6 +111,7 @@ class Mailer
* @param string $mailSignature
*
* @return $this
* @deprecated since version 4.8.0, to be removed with version 5.0.0
*/
public function setMailSignature($mailSignature)
{
......@@ -121,6 +124,7 @@ class Mailer
* @param string $htmlText
*
* @return $this
* @deprecated since version 4.8.0, to be removed with version 5.0.0
*/
public function setHtmlBody($htmlText)
{
......@@ -133,6 +137,7 @@ class Mailer
* @param string $urlWeb
*
* @return $this
* @deprecated since version 4.8.0, to be removed with version 5.0.0
*/
public function setUrlWeb($urlWeb)
{
......@@ -145,6 +150,7 @@ class Mailer
* @param bool $bcc
*
* @return $this
* @deprecated since version 4.8.0, to be removed with version 5.0.0
*/
public function setBcc($bcc)
{
......@@ -157,6 +163,7 @@ class Mailer
* @param string $subject
*
* @return $this
* @deprecated since version 4.8.0, to be removed with version 5.0.0
*/
public function setSubject($subject)
{
......@@ -169,6 +176,7 @@ class Mailer
* @param string $body
*
* @return $this
* @deprecated since version 4.8.0, to be removed with version 5.0.0
*/
public function setBody($body)
{
......@@ -181,6 +189,7 @@ class Mailer
* @param array|string $recipients
*
* @return $this
* @deprecated since version 4.8.0, to be removed with version 5.0.0
*/
public function setRecipients($recipients)
{
......@@ -193,6 +202,7 @@ class Mailer
* @param string $attachment
*
* @return $this
* @deprecated since version 4.8.0, to be removed with version 5.0.0
*/
public function setAttachments($attachment)
{
......@@ -205,6 +215,7 @@ class Mailer
* @param string $template
*
* @return $this
* @deprecated since version 4.8.0, to be removed with version 5.0.0
*/
public function setTemplate($template)
{
......@@ -213,6 +224,26 @@ class Mailer
return $this;
}
/**
* @param MailerMessage $data
* @return $this
*/
public function setData(MailerMessage $data)
{
$this
->setAttachments($data->getAttachments())
->setBody($data->getBody())
->setFrom($data->getFrom())
->setHtmlBody($data->getHtmlBody())
->setMailSignature($data->getMailSignature())
->setRecipients($data->getRecipients())
->setSubject($data->getSubject())
->setTemplate($data->getTemplate())
->setUrlWeb($data->getUrlWeb());
return $this;
}
/**
* Sends the email
*
......@@ -269,11 +300,11 @@ class Mailer
*/
private function generateBody()
{
if (!empty($this->htmlBody) && !empty($this->template)) {
if (!empty($this->template)) {
$mail = [
'charset' => 'UTF-8',
'title' => $this->subject,
'body' => $this->htmlBody,
'body' => !empty($this->htmlBody) ? $this->htmlBody : $this->stringFormatter->nl2p($this->body),
'signature' => $this->getHtmlSignature(),
'url_web_view' => $this->urlWeb
];
......@@ -288,8 +319,10 @@ class Mailer
if (!empty($this->body)) {
$this->phpMailer->AltBody = $this->decodeHtmlEntities($this->body . $this->getTextSignature());
} else {
$this->phpMailer->AltBody = $this->phpMailer->html2text($this->htmlBody . $this->getHtmlSignature(),
true);
$this->phpMailer->AltBody = $this->phpMailer->html2text(
$this->htmlBody . $this->getHtmlSignature(),
true
);
}
} else {
$this->phpMailer->Body = $this->decodeHtmlEntities($this->body . $this->getTextSignature());
......
<?php
/**
* Copyright (c) 2017 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Mailer;
class MailerMessage
{
/**
* @var string
*/
private $subject = '';
/**
* @var string
*/
private $body = '';
/**
* @var string
*/
private $htmlBody = '';
/**
* @var string
*/
private $urlWeb = '';
/**
* @var string
*/
private $mailSignature = '';
/**
* @var string|array
*/
private $from;
/**
* @var string|array
*/
private $recipients;
/**
* @var bool
*/
private $bcc = false;
/**
* @var array
*/
private $attachments = [];
/**
* @var string
*/
private $template = '';
/**
* @return string
*/
public function getSubject()
{
return $this->subject;
}
/**
* @param string $subject
* @return MailerMessage
*/
public function setSubject($subject)
{
$this->subject = $subject;
return $this;
}
/**
* @return string
*/
public function getBody()
{
return $this->body;
}
/**
* @param string $body
* @return MailerMessage
*/
public function setBody($body)
{
$this->body = $body;
return $this;
}
/**
* @return string
*/
public function getHtmlBody()
{
return $this->htmlBody;
}
/**
* @param string $htmlBody
* @return $this
*/
public function setHtmlBody($htmlBody)
{
$this->htmlBody = $htmlBody;
return $this;
}
/**
* @return string
*/
public function getUrlWeb()
{
return $this->urlWeb;
}
/**
* @param string $urlWeb
* @return $this
*/
public function setUrlWeb($urlWeb)
{
$this->urlWeb = $urlWeb;
return $this;
}
/**
* @return string
*/
public function getMailSignature()
{
return $this->mailSignature;
}
/**
* @param string $mailSignature
* @return $this
*/
public function setMailSignature($mailSignature)
{
$this->mailSignature = $mailSignature;
return $this;
}
/**
* @return array|string
*/
public function getFrom()
{
return $this->from;
}
/**
* @param array|string $from
* @return $this
*/
public function setFrom($from)
{
$this->from = $from;
return $this;
}
/**
* @return array|string
*/
public function getRecipients()
{
return $this->recipients;
}
/**
* @param array|string $recipients
* @return $this
*/
public function setRecipients($recipients)
{
$this->recipients = $recipients;
return $this;
}
/**
* @return bool
*/
public function isBcc()
{
return $this->bcc;
}
/**
* @param bool $bcc
* @return $this
*/
public function setBcc($bcc)
{
$this->bcc = $bcc;
return $this;
}
/**
* @return array
*/
public function getAttachments()
{
return $this->attachments;
}
/**
* @param array $attachments
* @return $this
*/
public function setAttachments($attachments)
{
$this->attachments = $attachments;
return $this;
}
/**
* @return string
*/
public function getTemplate()
{
return $this->template;
}
/**
* @param string $template
* @return $this
*/
public function setTemplate($template)
{
$this->template = $template;
return $this;
}
}
......@@ -9,6 +9,7 @@ namespace ACP3\Modules\ACP3\Contact\Model;
use ACP3\Core\Helpers\Secure;
use ACP3\Core\Helpers\SendEmail;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Mailer\MailerMessage;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\Contact\Installer\Schema;
......@@ -75,13 +76,14 @@ class ContactFormModel
$subject = $this->buildSubject('contact_subject', $systemSettings['site_title']);
$body = $this->buildEmailBody($formData, 'contact_body');
return $this->sendEmail->execute(
'',
$settings['mail'],
$formData['mail'],
$subject,
$body
);
$data = (new MailerMessage())
->setSubject($subject)
->setBody($body)
->setTemplate('Contact/layout.email.tpl')
->setRecipients($settings['mail'])
->setFrom($formData['mail']);
return $this->sendEmail->execute($data);
}
/**
......@@ -140,13 +142,17 @@ class ContactFormModel
$subject = $this->buildSubject('sender_subject', $systemSettings['site_title']);
$body = $this->buildEmailBody($formData, 'sender_body');
return $this->sendEmail->execute(
$formData['name'],
$formData['mail'],
$settings['mail'],
$subject,
$body
);
$data = (new MailerMessage())
->setSubject($subject)
->setBody($body)
->setTemplate('Contact/layout.email.tpl')
->setRecipients([
'name' => $formData['name'],
'email' => $formData['mail'],
])
->setFrom($settings['mail']);
return $this->sendEmail->execute($data);
}
/**
......
{extends file="asset:System/layout.email.tpl"}
{block EMAIL_HEAD}
<title>{$mail.title}</title>
{/block}
{block EMAIL_CONTENT}
{$mail.body}
{if !empty($mail.signature)}
<hr>
{$mail.signature}
{/if}
{/block}
......@@ -5,7 +5,7 @@
{/block}
{block EMAIL_CONTENT_BEFORE}
<p style="text-align:center">
<p class="text-center">
<a href="{$mail.url_web_view}">{lang t="newsletter|use_web_view"}</a>
</p>
{/block}
......@@ -13,6 +13,8 @@
{block EMAIL_CONTENT}
<h1>{$mail.title}</h1>
{$mail.body}
<hr>
{$mail.signature}
{if !empty($mail.signature)}
<hr>
{$mail.signature}
{/if}
{/block}
......@@ -6,15 +6,56 @@
<meta name=”x-apple-disable-message-reformatting”>
{block EMAIL_STYLESHEET}
<style type="text/css">
html, body {
margin: 0;
padding: 0;
}
body {
font-family: Arial, Helvetica, sans-serif;
background-color: #fff;
}
h1, h2, h3, h4, h5, h6, p {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
h1, h2, h3, h4, h5, h6 {
margin: 0;
padding: 0 0 10px;
}
h1, h2, h3, h4, h5, h6, strong {
color: #000;
font-weight: bold;
}
h1 {
font-size: 20px;
}
h2 {
font-size: 18px;
}
h3 {
font-size: 16px;
}
h4, h5, h6 {
font-size: 14px;
}
p {
color: #333;
font-size: 12px;
}
.email-content-wrapper {
width: 600px;
margin: 0 auto;
}
.text-left {
text-align: left;
}
.text-right {
text-align: right;
}
.text-center {
text-align: center;
}
.text-justify {
text-align: justify;
}
</style>
{/block}
</head>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment