Skip to content

Commit f5bb4e4

Browse files
committed
silent html2text conversion
1 parent a601995 commit f5bb4e4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Ip/Internal/Email/Module.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,12 @@ function send()
186186
$mail->IsHTML(true); // send as HTML
187187

188188
$mail->MsgHTML($email['email']);
189-
$mail->AltBody = \Ip\Internal\Text\Html2Text::convert($email['email']);
189+
try {
190+
$altBody = \Ip\Internal\Text\Html2Text::convert($email['email']);
191+
} catch (\Ip\Internal\Text\Html2TextException $e) {
192+
$altBody = $email['email'];
193+
}
194+
$mail->AltBody = $altBody;
190195
} else {
191196
/*$h2t = new \Ip\Internal\Text\Html2Text($content, false);
192197
$mail->Body = $h2t->get_text();*/

Ip/Internal/Text/Html2Text.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,18 @@ class Html2Text
4747
*/
4848
public static function convert($html)
4949
{
50+
if ($html == '') {
51+
return '';
52+
}
5053
$html = self::fix_newlines($html);
5154

5255
$doc = new \DOMDocument();
53-
if (!$doc->loadHTML($html))
56+
$prevValue = libxml_use_internal_errors(true);
57+
$loaded = $doc->loadHTML($html);
58+
libxml_use_internal_errors($prevValue);
59+
if (!$loaded) {
5460
throw new Html2TextException("Could not load HTML - badly formed?", $html);
61+
}
5562

5663
$output = self::iterate_over_node($doc);
5764

0 commit comments

Comments
 (0)