Skip to content

Commit d40e276

Browse files
committed
Add default Message charset
1 parent 081050b commit d40e276

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Message.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ protected function getCrlf() : string
133133
return "\r\n";
134134
}
135135

136+
protected function getCharset() : string
137+
{
138+
if (isset($this->mailer)) {
139+
return $this->mailer->getCharset();
140+
}
141+
return 'utf-8';
142+
}
143+
136144
public function setBoundary(string $boundary = null) : static
137145
{
138146
$this->boundary = $boundary ?? \bin2hex(\random_bytes(16));
@@ -271,7 +279,7 @@ protected function renderMessage(
271279
$crlf = $this->getCrlf();
272280
$part = '--alt-' . $this->getBoundary() . $crlf;
273281
$part .= 'Content-Type: ' . $contentType . '; charset='
274-
. $this->mailer->getCharset() . $crlf;
282+
. $this->getCharset() . $crlf;
275283
$part .= 'Content-Transfer-Encoding: base64' . $crlf . $crlf;
276284
$part .= \chunk_split($message) . $crlf;
277285
return $part;

tests/MessageTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,8 @@ public function testToString() : void
279279
$message = (string) new Message();
280280
self::assertStringContainsString('MIME-Version', $message);
281281
self::assertStringContainsString('Date', $message);
282+
$message = new Message();
283+
$message->setPlainMessage('Hello!');
284+
self::assertStringContainsString('charset=utf-8', (string) $message);
282285
}
283286
}

0 commit comments

Comments
 (0)