Skip to content

Commit

Permalink
do not always nl2br
Browse files Browse the repository at this point in the history
  • Loading branch information
JanST123 authored Jun 21, 2019
1 parent 8de1708 commit 2d92510
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <br /> 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
Expand Down Expand Up @@ -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 ."--";
}

Expand All @@ -70,4 +80,4 @@ public static function send(string $to, string $subject, string $body, array $ad
return $success;
}

}
}

0 comments on commit 2d92510

Please sign in to comment.