Mail_mime fun

From: Date: Mon, 24 Feb 2003 23:07:01 +0000
Subject: Mail_mime fun
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-3932@lists.php.net to get a copy of this message
Hi list! Pulling my hair out today trying to figure out why my multi-part messages are looking ugly in Eudora (and some other mail clients). The code driving Mail_mime is pretty intimidating (smarty is used to generate the dynamic contents of the mail), but I'm pretty sure it's correct. I basically get a text version, a subject, and a HTML version from smarty, stuff them into the appropriate places using setTXTBody() and setHTMLBody():
        $body_html = $mail_smarty->fetch("mail/html/$template");
        $body_text = $mail_smarty->fetch("mail/text/$template");
        $subject = $mail_smarty->fetch("mail/subjects/$template");
Then set the bodies:
        $mime->setTXTBody($body_text);
        $mime->setHTMLBody($body_html);
Then set Headers:
                $hdrs = array(
                                'From' => "\"$sender_name\"" . " <".trim($sender).">",
                                'Reply-To' => trim($sender),
                                'To' => trim($recipient),
                                'Subject' => trim($subject),
                                'X-Sender' => APP_NAME
                        );
and add an HTML image:
        if (PEAR::isError($tmp_result = $mime->addHTMLImage($img, "image/gif"))){
                                        logWarning("Problem adding image to html email. PEAR::Mail_mime says: " . $tmp_result->getMessage());
                                }
Then, as usual:
                $body = $mime->get();
                $hdrs = $mime->headers($hdrs);
And I send it out using Mail::Send():
                $mail =& Mail::factory("smtp", $param);
                $mail->send($recipient, $hdrs, $body); #minus error handling
The mail shows up as expected, but the end looks like: Table Test Column 1 Column 2 Content-Type: image/gif Content-Disposition: inline; filename="logo_home.gif" Content-ID: <b88d22bfb38cfaf32e5372beb4e0d315> <LOTS OF ENCODED GIF HERE> If I echo the results of Mime::get(), I see: --=_1ca1a2ce36f2a07d957dd77870a019ac Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit This is a test email that Tim sent via the DGN email subsystem. It ought to be multi-part mime with both HTML and text. The TestID of this email is 123456 --=_1ca1a2ce36f2a07d957dd77870a019ac Content-Type: multipart/related;
        boundary="=_8c1943154110f2fcbea2d3b6ebdc9b33"
--=_8c1943154110f2fcbea2d3b6ebdc9b33 Content-Type: text/html; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable This is a test email that Tim sent via the DGN email subsystem. It ought to be multi-part mime with both HTML and text. The TestID of this email is 123456 Here is an image 3de36bc5.jpg Table Test Column 1Column 2 --=_8c1943154110f2fcbea2d3b6ebdc9b33 Content-Type: image/gif Content-Transfer-Encoding: base64 Content-Disposition: inline; filename="logo_home.gif" Content-ID: <image data snipped> --=_8c1943154110f2fcbea2d3b6ebdc9b33-- --=_1ca1a2ce36f2a07d957dd77870a019ac-- Is this a Mail_mime() problem or a eudora problem? The results from mail_mime::get() look about right to me, and display ok on some webmail account I tried, but it breaks eudora. Any hints? TIA -Tim

« previous php.pear.general (#3932) next »