public function PHPMailer::html2text

5.x PHPMailer.php public PHPMailer::html2text($html, $advanced = false)

Convert an HTML string into plain text. This is used by msgHTML(). Note - older versions of this function used a bundled advanced converter which was removed for license reasons in #232. Example usage:

```php // Use default conversion $plain = $mail->html2text($html); // Use your own custom converter $plain = $mail->html2text($html, function($html) { $converter = new MyHtml2text($html); return $converter->get_text(); }); ```

Parameters

string $html The HTML text to convert:

bool|callable $advanced Any boolean value to use the internal converter,: or provide your own callable for custom conversion

Return value

string

1 call to PHPMailer::html2text()
PHPMailer::msgHTML in inc/PHPMailer/src/PHPMailer.php
Create a message body from an HTML string. Automatically inlines images and creates a plain-text version by converting the HTML, overwriting any existing values in Body and AltBody. Do not source $message content from user input! $basedir is prepended…

File

inc/PHPMailer/src/PHPMailer.php, line 3971

Class

PHPMailer
PHPMailer - PHP email creation and transport class.

Namespace

PHPMailer\PHPMailer

Code

public function html2text($html, $advanced = false) 
 {
  if (is_callable($advanced)) {
    return call_user_func($advanced, $html);
  }

  return html_entity_decode(
  trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))), 
  ENT_QUOTES, 
  $this->CharSet
  );
}