我可以阻止 MIME 嵌入的 html 图像作为附件出现吗?
这是我用来邮寄它的代码:
<?php
include('Mail.php');
include('Mail/mime.php');
$address = "Any old address will do";
$crlf = "\r\n";
$hdrs = array(
'From' => '[email protected]',
'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);
?>
图像显示在电子邮件中,但它也显示为附件。这有点笨拙,我可以阻止它吗?
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' => '[email protected]',
'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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到一个问题,某些邮件客户端会将所有内联图像呈现为空框。
我发现,如果未提供domainID,PEAR Mail_mime 类将尝试为您修复Content-ID 引用。
这会破坏 HTML 标记和 MIME 附件之间的链接。
这个答案帮助了我
因此,在发送电子邮件之前,将domainID 包含在Content-ID 中是最好的解决方案。
我循环发送了几封单独的电子邮件。每封电子邮件都应该是相同的,只是标题中的收件人在每次迭代时发生变化。我发现第一封电子邮件发送正确,然后在第二封及后续电子邮件中看到 Content-ID 的修改。
Outlook 中的初始测试并未发现该问题(图像正常)。仅在 Gmail 中进行测试才发现该故障。但是,如果 Gmail 检测到无效数据,它不会向您显示 src 属性,因此您无法仅通过 Gmail 中的电子邮件检查来发现问题。
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.
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.