0

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 an attachment. This is a bit clunky, can I prevent it?

Tzshand
  • 1,575
  • 11
  • 14
  • 2
    Not a solution to your problem, but I've always found it safer to host your email's images on the web somewhere, and have fully qualified links in your source. You would need hosting, though. – The Maniac Aug 19 '11 at 18:22
  • Aha! You mean reference it as http:// instead. Thanks! That worked. – Tzshand Aug 19 '11 at 19:02
  • I'm having same issue sending HTML from a MailBLaster application on my hosts server. THe images appear inline in the HTML email but are all strung on the bottom in Mac Mail and Gmail Web Browser interfaces which is ugly. Other Clients don't do it. Started happening maybe six months ago with same template. They changed something, I didn't! – wide_eyed_pupil Jul 02 '14 at 07:59

1 Answers1

0

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.

Community
  • 1
  • 1