From 2d92510d8f9a4e0229b47fb0281b4b384b277ac5 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 21 Jun 2019 15:14:16 +0200 Subject: [PATCH] do not always nl2br --- src/Email.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Email.php b/src/Email.php index 36fe10f..6d92811 100644 --- a/src/Email.php +++ b/src/Email.php @@ -23,7 +23,16 @@ private static function _init() { } - public static function send(string $to, string $subject, string $body, array $additionalHeaders=[]) :bool { + /** + * send the email, sends HTML E-Mail (with plain-text fallback) if detect body contains html + * @param string $to - the recipient + * @param string $subject + * @param string $body + * @param array $additionalHeaders - (optional headers) + * @param boolean nl2brforHTML - defaults to true, converts line breaks to
tags. can result in too many line break in html version + * @return boolean $success + */ + public static function send(string $to, string $subject, string $body, array $additionalHeaders=[], $nl2brforHTML=true) :bool { self::_init(); // detect html @@ -51,9 +60,10 @@ public static function send(string $to, string $subject, string $body, array $ad if ($isHtml) { $tmp = imap_8bit(nl2br($body)); + $tmpHTML = $nl2brforHTML ? imap_8bit(nl2br($body)) : imap_8bit($body); $body = "This is a MIME encoded message."; $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); - $body.="\r\n\r\n--" . $boundary ."\r\nContent-Type: text/html; charset=" . self::$charset . "\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n" . $tmp; + $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; $body.="\r\n\r\n--" . $boundary ."--"; } @@ -70,4 +80,4 @@ public static function send(string $to, string $subject, string $body, array $ad return $success; } -} \ No newline at end of file +}