SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    shows html code while sending mail problem ??

    Hello forums !!
    I am using my mail function to send the mail, mail successfully goes but the problem is its shows all the html codes and also the name is blank in the from section (Note: I am using outlook express)
    i had used the following code:
    PHP Code:
    <?php
    class Mailer{
        var 
    $to;
        var 
    $from;
        var 
    $cc;
        var 
    $bcc;
        var 
    $headers;
        var 
    $subject;
        var 
    $message;
        
        function 
    Mailer(){        
            
    $this->to "";        
            
    $this->from "";
            
    $this->cc "";        
            
    $this->bcc "";        
            
    // To send HTML mail, the Content-type header must be set
            
    $headers  'MIME-Version: 1.0' "\r\n";
            
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";        
            
    // Additional headers
            
    $headers .= 'To: '.$this->to "\r\n";
            
    $headers .= 'From: '.$this->from "\r\n";
            
    $headers .= 'Reply-To: '.$this->from "\r\n";
            
    $headers .= 'Cc: '.$this->cc "\r\n";
            
    $headers .= 'Bcc: '.$this->bcc "\r\n";
            
    $this->headers $headers;        
        }
        
        function 
    setSubject(){
            
    $this->subject "subjects goes here..";
        }
        
        function 
    setMessage($message){            
            
    # set Message
    $message = <<<EOF
    <html>
    <head>
    </head>
      <body> 
          
    <p>&nbsp;</p>
            <table width="455" border="0" align="center" cellpadding="0" cellspacing="10" bgcolor="#FFFFFF">    
                <tr>
                    <td width="88"><span class="field">Message</span></td>
                  <td width="289"><span class="fieldValue">
    $message</span></td>
                </tr>
                
            </table>
          
      </body>
    </html>
    EOF;
    $this->message $message;
        }
        
        function 
    sendMail(){
            return 
    mail($this->to$this->subject$this->message$this->headers);
        }

    }

    /**
     * Usage
     */

        
    $Mailer = new Mailer();
        
    $Mailer->setSubject();
        
    $Mailer->setMessage("Message goes here...");
        
    $Mailer->sendMail();    
    ?>
    How to make the code working (ie output should displayed as text not the code and also the from section should be visible (Note i m using outlook express))
    Thanks in advance to all of you

  2. #2
    SitePoint Addict
    Join Date
    May 2005
    Location
    London, ON
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to add the proper headers to tell the email client what to show if the user is HTML-enabled and what to show if they are not. Here is an example taken from a script I wrote for my university's research department that should get you started:

    PHP Code:
        //add From: header
        
    $headers "From: Research Funding <res-fund@uwo.ca>\r\n";
        
    //specify MIME version 1.0
        
    $headers .= "MIME-Version: 1.0\r\n";
        
    //unique boundary
        
    $boundary uniqid("HTMLDEMO");
        
    //tell e-mail client this e-mail contains alternate versions
        
    $headers .= "Content-Type: multipart/alternative" .
           
    "; boundary = $boundary\r\n\r\n";
        
    //message to people with clients who don't understand MIME
        
    $headers .= "This is a MIME encoded message.\r\n\r\n";
        
    //plain text version of message
        
    $headers .= "--$boundary\r\n" .
           
    "Content-Type: text/plain; charset=ISO-8859-1\r\n" .
           
    "Content-Transfer-Encoding: 7bit\r\n\r\n";
        
        
    //HTML version of message
        
    $headers .= "--$boundary\r\n" .
           
    "Content-Type: text/html; charset=ISO-8859-1\r\n" .
           
    "Content-Transfer-Encoding: 7bit\r\n\r\n"
    Ryan Price
    Subscribe to my blog for regular tips and tricks

  3. #3
    SitePoint Addict
    Join Date
    May 2005
    Location
    London, ON
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, I just did a quick search. I'm pretty sure this is the article I got my info from:

    http://www.zend.com/zend/trick/html-email.php
    Ryan Price
    Subscribe to my blog for regular tips and tricks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •