A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Multi part mail, how to?

  1. #1
    Senior Member Vincent26381's Avatar
    Join Date
    Feb 2003
    Location
    The Netherlands
    Posts
    833

    Multi part mail, how to?

    Hi,

    I'm building an Outlook clone in Flash for use online. It all works ok but to make it a bit better I would like it to send multipartmessages; html - plain text

    I work with a flash made HTML editor that outputs HTML 1.0

    I've found a PHP class online that converts HTML to plain text. What would I have to do to send messages multipart then, headers, mime type. Currently I use this:

    PHP Code:
    $sender "mymail@mydomain.com";
    $From "From: Me myself <$sender>";
    $Mime "MIME-Version: 1.0";
    $HTML "Content-type: text/html; charset=iso-8859-1";
    mail("$toaddress","subject","$body","$From\n$Mime\n$HTML"); 
    Some more questions on multi-part; Not getting it really from php.net; How would I get the plain text from a multipart message and how should I 'extract' (make links from) attachments?

    Thanks in advance
    Vincent
    SWIS BV

    Last edited by Markp.com on 07-23-2003 at 02:25 AM

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    I am using this code to send html mails:
    Code:
    <?
    class htmlmail
    {       var $bndtime;
            var $boundary, $boundary2;
            var $id, $pid;
            var $cids;
            var $recip;
            function htmlmail($recip)
            {       $this->pid = posix_getpid();
                    $this->bndtime = time();
                    $this->boundary = "PART.BOUNDARY." . $this->pid . ".musicman." . $this->bndtime;
                    $this->boundary2 = "PART.BOUNDARY.2." . $this->pid . ".musicman." . $this->bndtime;
                    $this->id = 1;
                    $this->cids = array();
                    $this->recip = $recip;
            }
            function newid()
            {       $this->id++;
                    return $this->pid . "_" . $this->bndtime . "_" . $this->id . "@musicman";
            }
            function gen_id($num)
            {       if(!isset($this->cids[$num]))
                            $this->cids[$num] = $this->newid();
                    return "\"cid:" . $this->cids[$num] . "\"";
            }
            function sendhtml($from, $subject, $plain, $html, $files)
            {       $headers = "From: $from\nMIME-Version: 1.0\nContent-type: multipart/related;\n\ttype=\"multipart/alternative\";\n\tboundary=\"{$this->boundary}\"";
                    $body = "tis is mime, ya know
    since this was made with free software I do not use this space to suggest
    buying a program
    
    --{$this->boundary}
    Content-type: multipart/alternative;
            boundary=\"{$this->boundary2}\"
    
    --{$this->boundary2}
    Content-type: text/plain
    
    " . $plain . "\n\n";
                    $html = preg_replace('/"CID(\d+)"/e', '$this->gen_id(\'\\1\')', $html);
                    $body .= "--{$this->boundary2}
    Content-type: text/html
    
    $html
    
    --{$this->boundary2}--
    
    ";
                    for($n = 0 ; $n < count($files) ; $n++)
                    {       $file = $files[$n];
                            if(isset($file[file]))
                            {       $name = ereg_replace(".*/", "", $file[file]);
                                    $fname = $file[file];
                                    $fp = fopen($fname, "r") or die("cannot open attachment $fname");
                                    $data = fread($fp, filesize($fname));
                                    fclose($fp);
                            }
                            else if(isset($file[data]))                        {       $data = $file[data];
                                    $name = $file[name];
                            }
                            else
                                    die('no file or data for attachment');
                            $body .= "--{$this->boundary}
    Content-ID: <{$this->cids[$n+1]}>
    Content-type: {$file[mime]}; name=\"{$name}\"
    Content-Transfer-Encoding: base64
    
    " . chunk_split(base64_encode($data)) . "\n\n";
                    }
                    $body .= "--{$this->boundary}--
    
    ";
                    mail($this->recip, $subject, $body, $headers);
            }
    }
    ?>
    There is no provision in this code for generating html from plain, or vice versa. It does allow, however, to send in-memory data as attachments

    Musicman

  3. #3
    Senior Member Vincent26381's Avatar
    Join Date
    Feb 2003
    Location
    The Netherlands
    Posts
    833
    It gives me a warning

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /opt/guide/www.avviso.nl/HTML/mailmusicman.php on line 40

    Parse error: parse error in /opt/guide/www.avviso.nl/HTML/mailmusicman.php on line 40

    line40: $html = preg_replace('/"CID(\d+)"/e', '$this->gen_id('\\1')', $html);

    Just to be sure, I take out $body and get that from posted vars from flash; $from and $recip and $subject just a posted var (?)

    Not sure what you mean by:

    send in-memory data as attachments

    How would that work... I'm using a (converted script) that was intended to connect to pop3/imap and read out messages. Still struggling with attachments from the mailserver. Would those be in memory?

    Thanks
    Vincent
    SWIS BV

    Last edited by Markp.com on 07-23-2003 at 02:25 AM

  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    tge original code had some more backslashes
    $html = preg_replace('/"CID(\d+)"/e', '$this->gen_id(\'\\1\')', $html);
    maybe boldfacing prevents their removal

    To attach a file, you could use
    $files = array(
    array(file => 'xy.jpg', mime => 'image/jpeg'),
    array(data => $myswf, name => 'generated.swf', mime => 'application/x-shockwave-flash')
    );
    This code was originally developed to create e-card swf on the fly and email it, so the swf would exists as a string. If you read data from mail server, you will more likely have them as strings within memory than as disk files.
    The CID mimikry is meant for images etc. inside a html message

    Musicman

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

HTML5 Development Center