Solved

Please help me with a Zend_Mail debugger class!

Posted on 2009-04-05
8
833 Views
Last Modified: 2013-11-10
Usage:

<?

    require("classes/class.Zend_Mail_Debugger.php");

    $mail=new Zend_Mail();
   
    $mail->addTo("nisse@sweden.net");
    $mail->setFrom("me@hotletter.com");
    $mail->setSubject("testing testing");
    $mail->setBodyHtml('
                       
        Hej! Jag är ett brev på svenska!<br>
        <br>
        (I\'m a swedish letter)<br>
        <br>
        Regards<br>
        <a href="http://www.nisses.se">Nisses.se</a>
                       
    ');
   
   
    Zend_Mail_Debugger::DumpToScreen($mail);
   
   
?>


Problem: How to make the mail readable on screen?
(see picture)

<?php
 
class Zend_Mail_Debugger{
 
 
    static function DumpToScreen(Zend_Mail $zfMail){
        
        echo "<table class='zf_mail_debug' border='1'>";
        
            echo "<tr>";
 
                echo "<th>";
                    echo "To:";
                echo "</th>";
                
                echo "<td>";
                    foreach($zfMail->getRecipients() as $r){
                        echo "$r"."; ";
                    }
                echo "</td>";
                
            echo "</tr>";
 
            echo "<tr>";
                echo "<th>";
                    echo "From:";
                echo "</th>";
                
                echo "<td>";
                    echo $zfMail->getFrom();
                echo "</td>";
            echo "</tr>";
 
            echo "<tr>";
                echo "<th>";
                    echo "Subject:";
                echo "</th>";
                                
                echo "<td>";
                    echo $zfMail->getSubject();
                echo "</td>";
            echo "</tr>";    
 
            echo "<tr>";
                echo "<th>";
                    echo "Text:";
                echo "</th>";
                                
                echo "<td>";
                    if($zfMail->getBodyHtml()){
                        echo  $zfMail->getBodyHtml(true);
                    }
                    else{
                        echo $zfMail->getBodyText();
                    }
                echo "</td>";
            echo "<tr>";                
                                                                
        
        echo "</table>";
        
        
        
    }
    
}
 
?>

Open in new window

output.png
0
Comment
Question by:davidsperling
  • 5
  • 3
8 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 24072104
What is the sense of making it readable to screen? If you want to debug the body text, than store your mail in a variable, then use setBodyText($variable):

<?php

    require("classes/class.Zend_Mail_Debugger.php");

    $mail=new Zend_Mail();
   
    $bodyHTML = '
                       
        Hej! Jag är ett brev på svenska!<br>
        <br>
        (I\'m a swedish letter)<br>
        <br>
        Regards<br>
        <a href="http://www.nisses.se">Nisses.se</a>
                       
    ';

    $mail->addTo("nisse@sweden.net");
    $mail->setFrom("me@hotletter.com");
    $mail->setSubject("testing testing");
    $mail->setBodyHtml($bodyHTML);
   
   
    echo '<blockquote>'.$bodyHTML.'</blockquote>';
?>
0
 
LVL 4

Author Comment

by:davidsperling
ID: 24072845
The reason is that i'm using Zend_Mail like this :-)

One class for each kind of mail, that is.


http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Frameworks/Q_24275092.html
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
ID: 24074453
When you are extending the class, you could just as well use a variable, but then put it as a property of your custom object, and just write a getter;

class HT_Mail_Walk_Match_To_Proposer_Swe extends Zend_Mail{
 
        private $_customBodyText = '';
                        
        function __construct($toEmail,$toUsrName,$fromEmail,$mateAnonName,$dateTime,$link,$linkCapt){
 
                //SOLUTION:
                parent::__construct(); //set default encoding etc (iso 8859)
                
                $this->setSubject("Hej på dig!");
                $this->addTo($toEmail,$toUsrName);
                $this->setFrom($fromEmail);
 
                
                $d=new dsDate($dateTime,"swe");
                 
                $weekday=$d->getWeekDayString();
                $monthDay=$d->getCustomFormat("j");
                $month=$d->getCustomFormat("F");
                $time=$d->getTimeString_1();
                
                $this->_customBodyText = '<body>
            Hej '.$toUsrName.'!<br/>
            
            '.$mateAnonName.' secret... åla öl etc  '.$weekday.' '.$monthDay.'  '.$month.' kl. '.$time.'!<br/>
            
            
            Vänligen gå in på <a href="'.$link.'">'.$linkCapt.'</a> och tacka Ja eller Nej!<br/>
            
            
            Hälsningar<br/>
            '.$linkCapt.'<br/>
            
            </body>';
 
 
            $this->setBodyHtml($this->_customBodyText);
                
                
                
        }
        
        function getMyBodyText() {
          return $this->_customBodyText;
        }
    
    
}

Open in new window

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 4

Author Comment

by:davidsperling
ID: 24081070
Sweet, but then I can't dump just any Zend_Mail object to screen, can I?

There must be a way to decrypt those cryptig writings?
(se pic)
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 24081154
You could do a forced download of a .eml file, but not sure what your browser thinks about that..
0
 
LVL 4

Author Comment

by:davidsperling
ID: 24084556
So there's no function like html_entities_decode() for this kind of encoding?

=0D=0A =0D=0A Hello!...

What's this encoding called anyway
0
 
LVL 4

Author Comment

by:davidsperling
ID: 24136022
The solution could maybe be found in Zend_Mime component...

(framework.zend.com)
0
 
LVL 4

Author Comment

by:davidsperling
ID: 24239434
Possible solution
Zend_Mime component

(framework.zend.com)

 
Haven't had the time to test. Thank's for the workarounds!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Configuring a checkbox in CSS and php 18 88
Testing a string condition in PHP 6 22
Wordpress errors showing up, hacked? 4 34
Google Maps API and PHP 25 30
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question