Skip to content

Commit 835480e

Browse files
authored
Merge pull request #87 from dotkernel/issue-85
Issue #85: Fixed attachment not working issue
2 parents 971c15f + 29928c7 commit 835480e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Service/LogService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Dot\Mail\Service;
66

7+
use DateTimeImmutable;
78
use Dot\Mail\Email;
89

9-
use function date;
1010
use function dirname;
1111
use function file_exists;
1212
use function file_put_contents;
@@ -56,7 +56,9 @@ public function sent(Email $message): false|int|null
5656
'cc' => $this->extractAddresses($message->getCc()),
5757
'bcc' => $this->extractAddresses($message->getBcc()),
5858
];
59-
$data = sprintf('[%s]: %s' . PHP_EOL, date('Y-m-d H:i:s'), json_encode($data));
59+
60+
$date = new DateTimeImmutable();
61+
$data = sprintf('[%s]: %s' . PHP_EOL, $date->format('Y-m-d H:i:s'), json_encode($data));
6062

6163
/**
6264
* Write the log data and return the result

src/Service/MailService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use function array_merge;
2323
use function basename;
2424
use function count;
25+
use function fopen;
2526
use function is_file;
2627
use function is_string;
2728

@@ -61,6 +62,7 @@ public function send(): ResultInterface
6162
//attach files before sending
6263
$this->attachFiles();
6364
$this->getTransport()->send($this->getMessage());
65+
$this->getMessage()->setBody(null);
6466

6567
$this->getEventManager()->triggerEvent($this->createMailEvent(MailEvent::EVENT_MAIL_POST_SEND, $result));
6668
} catch (Exception $e) {
@@ -102,7 +104,7 @@ public function attachFiles(): false|Email
102104
continue;
103105
}
104106
$basename = is_string($key) ? $key : basename($attachment);
105-
$attachedFile = new DataPart($attachment, $basename, null);
107+
$attachedFile = new DataPart(fopen($attachment, 'r'), $basename);
106108
$mimeMessage = new MixedPart($mimeMessage, $attachedFile);
107109

108110
$this->message->setBody($mimeMessage);

0 commit comments

Comments
 (0)