Skip to content

Commit

Permalink
silent html2text conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
maskas committed Sep 16, 2014
1 parent a601995 commit f5bb4e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Ip/Internal/Email/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,12 @@ function send()
$mail->IsHTML(true); // send as HTML

$mail->MsgHTML($email['email']);
$mail->AltBody = \Ip\Internal\Text\Html2Text::convert($email['email']);
try {
$altBody = \Ip\Internal\Text\Html2Text::convert($email['email']);
} catch (\Ip\Internal\Text\Html2TextException $e) {
$altBody = $email['email'];
}
$mail->AltBody = $altBody;
} else {
/*$h2t = new \Ip\Internal\Text\Html2Text($content, false);
$mail->Body = $h2t->get_text();*/
Expand Down
9 changes: 8 additions & 1 deletion Ip/Internal/Text/Html2Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@ class Html2Text
*/
public static function convert($html)
{
if ($html == '') {
return '';
}
$html = self::fix_newlines($html);

$doc = new \DOMDocument();
if (!$doc->loadHTML($html))
$prevValue = libxml_use_internal_errors(true);
$loaded = $doc->loadHTML($html);
libxml_use_internal_errors($prevValue);
if (!$loaded) {
throw new Html2TextException("Could not load HTML - badly formed?", $html);
}

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

Expand Down

0 comments on commit f5bb4e4

Please sign in to comment.