1
|
|
|
<?php |
2
|
|
|
namespace DERHANSEN\SfEventMgt\Service; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the TYPO3 CMS project. |
6
|
|
|
* |
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
9
|
|
|
* of the License, or any later version. |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please read the |
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
13
|
|
|
* |
14
|
|
|
* The TYPO3 project - inspiring people to share! |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
use \TYPO3\CMS\Core\Utility\GeneralUtility; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* EmailService |
21
|
|
|
* |
22
|
|
|
* @author Torben Hansen <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class EmailService |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Mailmessage |
29
|
|
|
* |
30
|
|
|
* @var \TYPO3\CMS\Core\Mail\MailMessage |
31
|
|
|
*/ |
32
|
|
|
protected $mailer = null; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Constructor - creates new instance of mailer |
36
|
|
|
*/ |
37
|
|
|
public function __construct() |
38
|
|
|
{ |
39
|
|
|
$this->mailer = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Sends an e-mail, if sender and recipient is an valid e-mail address |
44
|
|
|
* |
45
|
|
|
* @param string $sender The sender |
46
|
|
|
* @param string $recipient The recipient |
47
|
|
|
* @param string $subject The subject |
48
|
|
|
* @param string $body E-Mail body |
49
|
|
|
* @param string $name Optional sendername |
50
|
|
|
* |
51
|
|
|
* @return bool TRUE/FALSE if message is sent |
52
|
|
|
*/ |
53
|
|
|
public function sendEmailMessage($sender, $recipient, $subject, $body, $name = null) |
54
|
|
|
{ |
55
|
|
|
if (GeneralUtility::validEmail($sender) && GeneralUtility::validEmail($recipient)) { |
56
|
|
|
$this->mailer->setFrom($sender, $name); |
57
|
|
|
$this->mailer->setSubject($subject); |
58
|
|
|
$this->mailer->setBody($body, 'text/html'); |
59
|
|
|
$this->mailer->setTo($recipient); |
60
|
|
|
$this->mailer->send(); |
61
|
|
|
return $this->mailer->isSent(); |
62
|
|
|
} else { |
63
|
|
|
return false; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |