mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user