1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please read the |
7
|
|
|
* LICENSE.txt file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace DERHANSEN\SfEventMgt\Service; |
11
|
|
|
|
12
|
|
|
use TYPO3\CMS\Core\Mail\MailMessage; |
13
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* EmailService |
17
|
|
|
* |
18
|
|
|
* @author Torben Hansen <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class EmailService |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Sends an email, if sender and recipient is an valid email address |
24
|
|
|
* |
25
|
|
|
* @param string $sender The sender |
26
|
|
|
* @param string $recipient The recipient |
27
|
|
|
* @param string $subject The subject |
28
|
|
|
* @param string $body E-Mail body |
29
|
|
|
* @param string $name Optional sendername |
30
|
|
|
* @param array $attachments Array of files (e.g. ['/absolute/path/doc.pdf']) |
31
|
|
|
* @param string $replyTo The reply-to mail |
32
|
|
|
* |
33
|
|
|
* @return bool true/false if message is sent |
34
|
|
|
*/ |
35
|
|
|
public function sendEmailMessage( |
36
|
|
|
$sender, |
37
|
|
|
$recipient, |
38
|
|
|
$subject, |
39
|
|
|
$body, |
40
|
|
|
$name = null, |
41
|
|
|
$attachments = [], |
42
|
|
|
$replyTo = null |
43
|
|
|
) { |
44
|
|
|
if (!GeneralUtility::validEmail($sender) || !GeneralUtility::validEmail($recipient)) { |
45
|
|
|
return false; |
46
|
8 |
|
} |
47
|
|
|
|
48
|
8 |
|
/** @var MailMessage $email */ |
49
|
4 |
|
$email = GeneralUtility::makeInstance(MailMessage::class); |
50
|
4 |
|
$email->setFrom($sender, $name); |
51
|
4 |
|
$email->setTo($recipient); |
52
|
4 |
|
$email->setSubject($subject); |
53
|
4 |
|
$email->html($body); |
54
|
4 |
|
if ($replyTo !== null && $replyTo !== '') { |
55
|
4 |
|
$email->setReplyTo($replyTo); |
56
|
4 |
|
} |
57
|
|
|
foreach ($attachments as $attachment) { |
58
|
4 |
|
if (file_exists($attachment)) { |
59
|
|
|
$email->attachFromPath($attachment); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $email->send(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|