Results 1 to 3 of 3

Thread: Emails as html

  1. #1

    Thread Starter
    Addicted Member thamizhinpan's Avatar
    Join Date
    Dec 2005
    Location
    TE
    Posts
    243

    Emails as html

    I want to send emails as html.
    But
    PHP Code:
    mail 
    function send emails as plain text.
    Can I send email as html with "mail" function?
    If above question or answer will help to you
    Don't forget to rate me
    தமிழ்இன்பன்

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Emails as html

    Yes you can. You need you need to send the email as an MIME (Muiltipart Internet Mail Extensions) type. The HTML portion of the email is actually an inline attachment.

    This tutorial shows how it is done:

    http://www.sitepoint.com/article/advanced-email-php/3
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    Junior Member teamer's Avatar
    Join Date
    May 2006
    Posts
    17

    Re: Emails as html

    Here's a code i found on PHP.net once ... it helped me alot ... you even can send attachments via it :-)
    Code:
    <?php
    $boundary = '-----=' . md5( uniqid ( rand() ) );
    ?>
    
    You can attach a Word document if you specify:
    <?php
    $message .= "Content-Type: application/msword; name=\"my attachment\"\n";
    $message .= "Content-Transfer-Encoding: base64\n";
    $message .= "Content-Disposition: attachment; filename=\"$theFile\"\n\n";
    ?>
    
    When adding a file you must open it and read it with fopen and add the content to the message:
    <?php
    $path = "whatever the path to the file is";
    $fp = fopen($path, 'r');
    do //we loop until there is no data left
    {
            $data = fread($fp, 8192);
            if (strlen($data) == 0) break;
            $content .= $data;
          } while (true);
    $content_encode = chunk_split(base64_encode($content));
    $message .= $content_encode . "\n";
    $message .= "--" . $boundary . "\n";
    ?>
    
    Add the needed headers and send!
    <?php
    $headers  = "From: \"Me\"<[email protected]>\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
    mail('[email protected]', 'Email with attachment from PHP', $message, $headers);
    ?>
    
    Finally, if you add an image and want it displayed in your email, change the Content-Type from attachment to inline:
    
    <?php
    $message .= "Content-Disposition: inline; filename=\"$theFile\"\n\n";
    ?>
    Enjoy !

Posting Permissions

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



Click Here to Expand Forum to Full Width