Pimcore\Helper\Mail::getDebugInformation PHP Метод

getDebugInformation() публичный статический Метод

public static getDebugInformation ( $type, Mail $mail ) : string
$type
$mail Pimcore\Mail
Результат string
    public static function getDebugInformation($type, MailClient $mail)
    {
        $type = strtolower($type);
        if ($type != 'html' && $type != 'text') {
            throw new \Exception('$type has to be "html" or "text"');
        }
        $temporaryStorage = $mail->getTemporaryStorage();
        //generating html debug info
        if ($type == 'html') {
            $debugInformation = '<br/><br/><table class="pimcore_debug_information">
                                    <tr><th colspan="2">Debug information</th></tr>';
            $debugInformation .= '<tr><td class="pimcore_label_column">From:</td><td>';
            if ($mail->getFrom()) {
                $debugInformation .= $mail->getFrom();
            } else {
                $defaultFrom = $mail->getDefaultFrom();
                $debugInformation .= $defaultFrom["email"] . '<br/>Info: No "from" email address given so the default "from" email address is used from "Settings" -> "System" -> "Email Settings" )';
            }
            $debugInformation .= '</td></tr>';
            foreach (['To', 'Cc', 'Bcc'] as $key) {
                if (isset($temporaryStorage[$key]) && is_array($temporaryStorage[$key])) {
                    $debugInformation .= '<tr><td class="pimcore_label_column">' . $key . ': </td>';
                    $debugInformation .= '<td>' . self::formatDebugReceivers($temporaryStorage[$key]) . '</td></tr>';
                }
            }
            $debugInformation .= '</table>';
        } else {
            //generating text debug info
            $debugInformation = "\r\n  \r\nDebug Information:  \r\n  \r\n";
            if ($mail->getFrom()) {
                $debugInformation .= 'From: ' . $mail->getFrom() . "\r\n";
            } else {
                $defaultFrom = $mail->getDefaultFrom();
                $debugInformation .= 'From: ' . $defaultFrom["email"] . ' (Info: No "from" email address given so the default "from" email address is used from "Settings" -> "System" -> "Email Settings" )' . "\r\n";
            }
            //generating text debug info
            $debugInformation = "\r\n  \r\nDebug Information:  \r\n  \r\n";
            foreach (['To', 'Cc', 'Bcc'] as $key) {
                if (isset($temporaryStorage[$key]) && is_array($temporaryStorage[$key])) {
                    $debugInformation .= "{$key}: " . self::formatDebugReceivers($temporaryStorage[$key]) . "\r\n";
                }
            }
        }
        return $debugInformation;
    }

Usage Example

Пример #1
0
 /**
  * @throws \Exception
  * @throws \Zend_Mail_Exception
  */
 protected function checkDebugMode()
 {
     if (\Pimcore::inDebugMode()) {
         if (empty(self::$debugEmailAddresses)) {
             throw new \Exception('No valid debug email address given in "Settings" -> "System" -> "Email Settings"');
         }
         if ($this->preventDebugInformationAppending != true) {
             //adding the debug information to the html email
             $html = $this->getBodyHtml();
             if ($html instanceof \Zend_Mime_Part) {
                 $rawHtml = $html->getRawContent();
                 $debugInformation = MailHelper::getDebugInformation('html', $this);
                 $debugInformationStyling = MailHelper::getDebugInformationCssStyle();
                 $rawHtml = preg_replace("!(</\\s*body\\s*>)!is", "{$debugInformation}\\1", $rawHtml);
                 $rawHtml = preg_replace("!(<\\s*head\\s*>)!is", "\\1{$debugInformationStyling}", $rawHtml);
                 $this->setBodyHtml($rawHtml);
             }
             $text = $this->getBodyText();
             if ($text instanceof \Zend_Mime_Part) {
                 $rawText = $text->getRawContent();
                 $debugInformation = MailHelper::getDebugInformation('text', $this);
                 $rawText .= $debugInformation;
                 $this->setBodyText($rawText);
             }
             //setting debug subject
             $subject = $this->getSubject();
             $this->clearSubject();
             $this->setSubject('Debug email: ' . $subject);
         }
         $this->clearRecipients();
         $this->addTo(self::$debugEmailAddresses);
     }
 }