Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
TYPO3
sg_mail
Commits
a2b5fb6b
Commit
a2b5fb6b
authored
Sep 30, 2016
by
Torsten Oppermann
Browse files
[TASK] Refactoring Test Mail & Controller for DB implementation. Fixed some bugs
parent
51822813
Changes
3
Hide whitespace changes
Inline
Side-by-side
Classes/Controller/MailController.php
View file @
a2b5fb6b
...
...
@@ -98,6 +98,8 @@ class MailController extends ActionController {
);
}
$this
->
view
->
assign
(
'selectedLanguageLeft'
,
$this
->
settings
[
'templateDefaultLanguage'
]);
$this
->
view
->
assign
(
'selectedLanguageRight'
,
$this
->
settings
[
'templateDefaultLanguage'
]);
$this
->
view
->
assign
(
'selectedTemplateKey'
,
$secondLevelFirstEntry
);
$this
->
view
->
assign
(
'selectedExtensionKey'
,
$firstEntry
);
}
...
...
Classes/Service/MailTemplateService.php
View file @
a2b5fb6b
...
...
@@ -3,7 +3,9 @@
namespace
SGalinski\SgMail\Service
;
use
SGalinski\SgMail\Domain\Model\Mail
;
use
SGalinski\SgMail\Domain\Model\Template
;
use
SGalinski\SgMail\Domain\Repository\MailRepository
;
use
TYPO3\CMS\Core\Exception
;
use
TYPO3\CMS\Core\Mail\MailMessage
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Extbase\Object\ObjectManager
;
...
...
@@ -110,6 +112,12 @@ class MailTemplateService {
*/
private
$bccAddresses
=
[];
/**
* @var \SGalinski\SgMail\Domain\Repository\TemplateRepository
* @inject
*/
protected
$templateRepository
=
NULL
;
/**
* MailTemplateService constructor.
*/
...
...
@@ -125,9 +133,27 @@ class MailTemplateService {
$this
->
mailMessage
->
setFrom
(
$this
->
fromAddress
);
$this
->
bccAddresses
=
GeneralUtility
::
trimExplode
(
','
,
$this
->
tsSettings
[
'mail'
][
'default'
][
'bcc'
]);
$this
->
bccAddresses
=
GeneralUtility
::
trimExplode
(
','
,
$this
->
tsSettings
[
'mail'
][
'default'
][
'cc'
]);
$this
->
mailMessage
->
setBcc
(
$this
->
bccAddresses
);
$this
->
mailMessage
->
setBcc
(
$this
->
ccAddresses
);
$this
->
ccAddresses
=
GeneralUtility
::
trimExplode
(
','
,
$this
->
tsSettings
[
'mail'
][
'default'
][
'cc'
]);
foreach
(
$this
->
bccAddresses
as
$index
=>
$email
)
{
if
(
!
filter_var
(
$email
,
FILTER_VALIDATE_EMAIL
))
{
unset
(
$this
->
bccAddresses
[
$index
]);
}
}
foreach
(
$this
->
ccAddresses
as
$index
=>
$email
)
{
if
(
!
filter_var
(
$email
,
FILTER_VALIDATE_EMAIL
))
{
unset
(
$this
->
ccAddresses
[
$index
]);
}
}
if
(
sizeof
(
$this
->
bccAddresses
)
>
0
)
{
$this
->
mailMessage
->
setBcc
(
$this
->
bccAddresses
);
}
if
(
sizeof
(
$this
->
ccAddresses
)
>
0
)
{
$this
->
mailMessage
->
setCc
(
$this
->
ccAddresses
);
}
}
/**
...
...
@@ -164,13 +190,16 @@ class MailTemplateService {
* Send the Email
*/
public
function
sendEmail
()
{
$templateEntry
=
self
::
$registerArray
[
$this
->
extensionKey
][
$this
->
templateName
];
$objectManager
=
GeneralUtility
::
makeInstance
(
ObjectManager
::
class
);
/** @var StandaloneView $emailView */
$emailView
=
$objectManager
->
get
(
StandaloneView
::
class
);
$emailView
->
setTemplatePathAndFilename
(
$templateEntry
[
'templatePath'
]
.
$this
->
language
.
'.sg_mail.locallang.html'
);
/** @var Template $template */
$template
=
$this
->
templateRepository
->
findTemplate
(
$this
->
extensionKey
,
$this
->
templateName
,
$this
->
language
)
->
getFirst
();
$emailView
->
setTemplateSource
(
$template
->
getContent
());
$emailView
->
assignMultiple
(
$this
->
markers
);
$emailBody
=
$emailView
->
render
();
...
...
@@ -179,7 +208,7 @@ class MailTemplateService {
$emailBody
=
nl2br
(
$emailBody
);
$emailBody
=
preg_replace
(
'/(<br[\s]?[\/]?>[\s]*){3,}/'
,
'<br /><br />'
,
$emailBody
);
$this
->
mailMessage
->
setSubject
(
$t
his
->
s
ubject
);
$this
->
mailMessage
->
setSubject
(
$t
emplate
->
getS
ubject
()
);
$this
->
mailMessage
->
setBody
(
$emailBody
,
'text/html'
);
$this
->
mailMessage
->
send
();
}
else
{
...
...
@@ -327,5 +356,4 @@ class MailTemplateService {
return
$this
;
}
}
Configuration/TypoScript/setup.ts
View file @
a2b5fb6b
...
...
@@ -10,7 +10,7 @@ module.tx_sgmail {
test
.
from
=
info
@
test
.
de
test
.
subject
=
This
is
just
a
Test
E
-
Mail
default
.
from
=
default
.
from
=
torsten
@
sgalinski
.
de
default
.
bcc
=
default
.
cc
=
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment