You are here

public function PHPMailer::MsgHTML in SMTP Authentication Support 7.2

Same name and namespace in other branches
  1. 7 smtp.phpmailer.inc \PHPMailer::MsgHTML()

Evaluates the message and returns modifications for inline images and backgrounds @access public

Return value

$message

File

./smtp.phpmailer.inc, line 1996
The mail handler class in smtp module, based on code of the phpmailer library, customized and relicensed to GPLv2.

Class

PHPMailer
PHPMailer - PHP email transport class NOTE: Requires PHP version 5 or later @package PHPMailer @author Andy Prevost @author Marcus Bointon @copyright 2004 - 2009 Andy Prevost

Code

public function MsgHTML($message, $basedir = '') {
  preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
  if (isset($images[2])) {
    foreach ($images[2] as $i => $url) {

      // do not change urls for absolute images (thanks to corvuscorax)
      if (!preg_match('#^[A-z]+://#', $url)) {
        $filename = basename($url);
        $directory = dirname($url);
        $directory == '.' ? $directory = '' : '';
        $cid = 'cid:' . md5($filename);
        $ext = pathinfo($filename, PATHINFO_EXTENSION);
        $mimeType = self::_mime_types($ext);
        if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
          $basedir .= '/';
        }
        if (strlen($directory) > 1 && substr($directory, -1) != '/') {
          $directory .= '/';
        }
        if ($this
          ->AddEmbeddedImage($basedir . $directory . $filename, md5($filename), $filename, 'base64', $mimeType)) {
          $message = preg_replace("/" . $images[1][$i] . "=\"" . preg_quote($url, '/') . "\"/Ui", $images[1][$i] . "=\"" . $cid . "\"", $message);
        }
      }
    }
  }
  $this
    ->IsHTML(TRUE);
  $this->Body = $message;
  $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\\/\\1>/s', '', $message)));
  if (!empty($textMsg) && empty($this->AltBody)) {
    $this->AltBody = html_entity_decode($textMsg);
  }
  if (empty($this->AltBody)) {
    $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
  }
}