开发者

Can I prevent a MIME embedded html image from appearing as an attachment?

Here is the code I am using to mail it:

<?php
include('Mail.php');
include('Mail/mime.php');

$address = "Any old address will do";
$crlf = "\r\n";
$hdrs = array( 
    'From' => 'do-not-reply@mydomain.com', 
    'Subject' => 'Mail_mime test message' 
    ); 

$mime = new Mail_mime($crlf); 

$mime->addHTMLImage("emailHeader.jpg", "image/jpg");

$cid=$mime->_html_images[0]['cid'];

$html = '<html><body><center><img src="cid:'.$cid.'">This image shows up just fine</center></body></html>';
$text = 'Plain text version of email';

$mime->setTXTBody($text);
$mime->setHTMLBody($html); 

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory('mail');
$mail->send($address, $hdrs, $body);

?>

The image shows up in the email, but it is also shows up as a开发者_StackOverflown attachment. This is a bit clunky, can I prevent it?


I had an issue where some mail clients would render all inline images as empty boxes.

What I found out is that the PEAR Mail_mime class will attempt to fix your Content-ID references for you if a domainID is not provided.

    e.g.
    [HTML] src="123456.jpg" 
    [Headers] Content-ID: <123456.jpg>
    updates to
    [HTML] src="cid:123456.jpg@domain.com" 
    [Headers] Content-ID: <123456.jpg@domain.com>
    BUT
    [HTML] src="cid:123456.jpg" 
    [Headers] Content-ID: <123456.jpg>
    updates to
    [HTML] src="cid:123456.jpg" 
    [Headers] Content-ID: <123456.jpg@domain.com>

Which breaks the link between the HTML tag and the MIME attachment.

This answer helped me out

So including the domainID in the Content-ID yourself before sending the email is the best solution.

I was sending out several separate emails in a loop. Each email was meant to be the same with just the recipients in the header changing for each iteration. I found that the first email was sent correctly and then the munging of the Content-ID was seen on the second and subsequent emails.

Initial testing in Outlook did not uncover the issue (images were fine). Only testing in Gmail revealed the glitch. However Gmail will not show you the src attribute if it detects invalid data so you can't see the problem just with Inspect on the email in Gmail.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜