$MimeMesg = new Mail_mime();
$MimeMesg->setTxtBody($MessageBody);
$MimeMesg->setHTMLBody($filledInTemplate);
$MimeMesg->addHTMLImage($entry,'image/jpeg');
$headers = array( 'From' => $From,
'Subject' => $Subject);
$MimeMesgHead = $MimeMesg->headers($headers);
$MimeMesgBody = $MimeMesg->get();
$mail =& Mail::factory('mail');
$mail->send($Recipients,$MimeMesgHead,$MimeMesgBody);
But when the message arrives in my mailbox, my mail cleint reads it as
a big hunk of text (also, the image seems to not be attached).
So I checked the message headers. What I found was that there was no
Content-Type set, no encoding, and no content boundary defined. The
first two are easy enough to fix... I just change my headers array
like so:
$headers = array( 'From' => $From,
'Subject' => $Subject,
'Content-Type' => 'multipart/mixed',
'Content-Transfer-Encoding' => '7bit', );
But here's the thing... the boundary *is* getting automatically
generated for the body... and I don't know how to pull that specific
boundary in the header. Yes, I guess I can pull it out with a regexp
or something. I was just hoping to avoid having to do stuff like this
(and like setting the Content-Type and Encoding for the whole mail
message manually) by using the class.
Is my understanding of how Mail_mime works off, or is the class
somewhat broken?
regards,
Weston
A while back I struggled with Mail_mime too. At the time the docs
didn't seem to provide a good sample HTML email that included a
graphic. So, I've pasted pared down a function I used in the
construction of Papaya Polls (http://www.papayapolls.com/index.php) at
the end of this post. I've deleted quite a lot of it, but I think you
can use it as a good reference.
I think you've missed a parameter in the "addHTMLImage" call.
Everything else looks OK to me... but I don't claim to be an expert.
Good Luck.
Leonard
http://www.perceptus.ca/
function sendConfirm($email, $username,$fname, $lname, $password){
// PEARifying to send (proper) mixed HTML/Text.
include_once('Mail.php'); // PEAR
include_once('Mail/mime.php'); // PEAR
$imagename = $GLOBALS['ESPCONFIG']['email_logo'];
// path and filename of image - FILE path, not URL
$imagefile =
$GLOBALS['ESPCONFIG']['prefix'] . '/images/' . $imagename;
$to = "$fname $lname <$email>";
$subject = "Thank you for registering with ${ourName}";
/* message */
$html = "<html><body><p>Welcome to $ourName... </p>
<img src=\"${imagename}\"></body></html>";
// way to get text format - for those not using HTML email.
$text=strip_tags($html);
//   s not stripped - do it now. =)
$text=ereg_replace(' ', ' ', $text);
// try to save a few bytes of line breaks and tabs.
$html=ereg_replace("[\r\t\n]","",$html);
$from_name="$ourName - Customer Support";
$from_address=$csEmail;
$crlf = "\r\n";
$hdrs = array('From' => "$from_name <$from_address>",
'BCC' => "<$csEmail>", 'Subject' => $subject );
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
//$mime->addAttachment($file); // works, but not used here.
$mime->addHTMLImage($imagefile, "image/jpg",$imagename);
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail =& Mail::factory('mail');
$ok=$mail->send($to, $hdrs, $body);
} //end f:sendConfirmed
On 11 Jul 2003 23:27:32 -0700,
notsew-reversePrec...@canncentral.org (Weston C)
wrote: