Skip to content

Commit f1b208a

Browse files
authored
better plain text emails
1 parent 2d92510 commit f1b208a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Email.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,19 @@ public static function send(string $to, string $subject, string $body, array $ad
5959
);
6060

6161
if ($isHtml) {
62-
$tmp = imap_8bit(nl2br($body));
62+
$tmp = imap_8bit(
63+
preg_replace('/^\h+/m', '',
64+
html_entity_decode(
65+
strip_tags(
66+
preg_replace('/^\s*(<[^>]+>\s*)+\r?\n/m', '', $body)
67+
)
68+
)
69+
)
70+
);
71+
6372
$tmpHTML = $nl2brforHTML ? imap_8bit(nl2br($body)) : imap_8bit($body);
6473
$body = "This is a MIME encoded message.";
65-
$body.="\r\n\r\n--" . $boundary ."\r\nContent-Type: text/plain; charset=" . self::$charset . "\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n" . strip_tags($tmp);
74+
$body.="\r\n\r\n--" . $boundary ."\r\nContent-Type: text/plain; charset=" . self::$charset . "\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n" . $tmp;
6675
$body.="\r\n\r\n--" . $boundary ."\r\nContent-Type: text/html; charset=" . self::$charset . "\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n" . $tmpHTML;
6776
$body.="\r\n\r\n--" . $boundary ."--";
6877
}

0 commit comments

Comments
 (0)