Detect sending non-html emails as html (#13114)

* Detect sending non-html emails as html
and use <br /> for line returns instead of \r\n

* Fix style
This commit is contained in:
Tony Murray
2021-08-09 09:17:32 -05:00
committed by GitHub
parent d6039399fa
commit 2b8eb74b7a

View File

@@ -35,9 +35,17 @@ class Mail extends Transport
public function contactMail($obj)
{
$email = $this->config['email'] ?? $obj['contacts'];
$msg = preg_replace("/(?<!\r)\n/", "\r\n", $obj['msg']); // fix line returns for windows mail clients
$html = Config::get('email_html');
return send_mail($email, $obj['title'], $msg, (Config::get('email_html') == 'true') ? true : false);
if ($html && ! $this->isHtmlContent($obj['msg'])) {
// if there are no html tags in the content, but we are sending an html email, use br for line returns instead
$msg = preg_replace("/\r?\n/", "<br />\n", $obj['msg']);
} else {
// fix line returns for windows mail clients
$msg = preg_replace("/(?<!\r)\n/", "\r\n", $obj['msg']);
}
return send_mail($email, $obj['title'], $msg, $html);
}
public static function configTemplate()
@@ -56,4 +64,9 @@ class Mail extends Transport
],
];
}
private function isHtmlContent($content): bool
{
return $content !== strip_tags($content);
}
}