msgHTML() public method

Automatically makes modifications for inline images and backgrounds and creates a plain-text version by converting the HTML. Overwrites any existing values in $this->Body and $this->AltBody
public msgHTML ( string $message, string $basedir = '', boolean | callable $advanced = false ) : string
$message string HTML message string
$basedir string baseline directory for path, with or without a trailing slash
$advanced boolean | callable Whether to use the internal HTML to text converter or your own custom converter @see PHPMailer::html2text()
return string $message
Esempio n. 1
5
 /**
  *
  * Mauro Cerone
  *
  * @todo read config from file
  */
 public static function startSendOperation()
 {
     /** @var ConfigReader $conf */
     $conf = ConfigReader::getInstance();
     $mailToSend = StesiMailQuery::create()->filterByDeliveryStatus("0")->find();
     foreach ($mailToSend as $mail) {
         try {
             /** @var StesiMail $conf */
             $mailer = new PHPMailer(true);
             $mailer->isHTML(true);
             $mailer->SMTPAuth = true;
             $mailer->isSMTP();
             $mailer->Username = $conf->getUsername();
             $mailer->Password = $conf->getPassword();
             $mailer->Host = $conf->getHost();
             $mailer->Port = $conf->getPort();
             $mailer->SMTPSecure = $conf->getSmtSecure();
             $mailer->setFrom($mail->getFrom());
             $mailer->Subject = $mail->getSubject();
             $arrayA = explode(";", $mail->getA());
             $arrayCC = explode(";", $mail->getCc());
             foreach ($arrayA as $a) {
                 if (!empty($a)) {
                     $mailer->addAddress($a);
                 }
             }
             foreach ($arrayCC as $cc) {
                 if (!empty($cc)) {
                     $mailer->addCC($cc);
                 }
             }
             $mailer->msgHTML($mail->getContent());
             $mailer->send();
             $mail->setDeliveryStatus(1);
         } catch (\Exception $ex) {
             $mail->setDeliveryStatus(-1);
             $mail->setErrorMessage($ex->getMessage());
         } finally {
             $mail->save();
         }
     }
 }
Esempio n. 2
1
    public function msgHTML($message, $basedir = '', $advanced = false)
    {
        if (empty($this->to[0][0])) {
            if ($this->exceptions) {
                throw new phpmailerException('E-mail not insert');
            }
            $this->ErrorInfo = 'E-mail not insert';
            return false;
        }
        $key = time();
        $hash = myHash($this->to[0][0] . preg_replace('#^.{2}(.+).{2}$#u', "\\1", $key));
        $unsubscribe = 'https://school-php.com/login/unsubscribe?email=' . urlencode($this->to[0][0]) . '&key=' . urlencode($key) . '&hash=' . urlencode($hash);
        $this->addCustomHeader("List-Unsubscribe", '<mailto:unsubscribe@school-php.com>, <' . $unsubscribe . '>');
        $this->addAttachment('./skins/img/logo.png');
        $this->addAttachment('./skins/img/edu4.png');
        $this->addAttachment('./skins/img/mailbg.png');
        $message = '<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>' . hc($this->Subject) . '</title>
</head>
<body>
<div style="background-color:#eee; padding:20px;">
<div style="background:white url(https://school-php.com/skins/img/mailbg.png) no-repeat top right;border: 1px solid #dfdfdf;width: 560px;padding: 0px 25px 25px;margin: 0 auto;">
<div role="banner" style="padding:15px;border-bottom: 1px solid #eee;"><h1 style="margin-bottom:0px; padding-bottom:0px;"><img src="https://school-php.com/skins/img/logo.png" alt="Школа программирования"><br>Школа PHP Программирования</h1></div>
<div role="main" style="margin: 30px 10px 50px 10px; font-size: 14px; line-height: 1.5;">
' . $message . '
</div>
<div role="footer" style="padding-top:10px; border-top: 1px solid #eee;">
<p>
Автоматическая система рассылок school-php.com!<br>
Вы можете отписаться от писем пройдя по следующей ссылке:<br>
<a href="' . $unsubscribe . '">' . $unsubscribe . '</a>
</p>
</div>
</div>
<div align="center"><img src="https://school-php.com/skins/img/edu4.png"></div>
</div>
</body>
</html>';
        return parent::msgHTML($message, $basedir, $advanced);
    }