0
有很多像这样的问题,但问题是他们每个人都建议使用某种第三方库。这对我来说不是一种选择,因为我们使用内部排队系统,在这个系统中,电子邮件会被发送到我们的数据库中,直到它被发送。如何手动在电子邮件中嵌入图像?
如何在不使用第三方软件的情况下将图像嵌入到电子邮件中?
有很多像这样的问题,但问题是他们每个人都建议使用某种第三方库。这对我来说不是一种选择,因为我们使用内部排队系统,在这个系统中,电子邮件会被发送到我们的数据库中,直到它被发送。如何手动在电子邮件中嵌入图像?
如何在不使用第三方软件的情况下将图像嵌入到电子邮件中?
通常情况下,如果附加的图像使用以下MIME头的电子邮件,这将提供给text/html
为图像:
Content-Type: image/jpeg
Attachment-Disposition: inline; filename=MYIMAGE.JPG
然后在邮件正文:
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit
<html>
<!-- HTML tags -->
<img src="MYIMAGE.JPG" />
<!-- more HTML tags -->
</html>
我正在使用香草PHP发送内嵌嵌入式图像的电子邮件。代码的核心是这样的:
$from = "$from_name <$from_email>";
$reply = "$replyto_name <$replyto_email>";
$to = "$to_name <$to_email>";
$main_boundary = substr(sha1(rand()), 0, 20);
$part_boundary = substr(sha1(rand()), 0, 20);
$headers = "From: $from\n";
$headers .= "Reply-To: $reply\n";
$headers .= "X-Mailer: PHP script mailer\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= 'Content-Type: multipart/alternative;'."\n".' boundary="'.$main_boundary.'"'."\n";
$message=
'This is a multi-part message in MIME format.
--'.$main_boundary.'
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
'.$msgTXT.'
--'.$main_boundary.'
Content-Type: multipart/related;
boundary="'.$part_boundary.'"
--'.$part_boundary.'
Content-Type: text/html; UTF-8
Content-Transfer-Encoding: 7bit
'.$msgHTML.'
--'.$part_boundary.'
Content-Type: image/png; name="logo.png"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="logo.png"
Content-ID: <[email protected]>
<base64 encoded image here>
--'.$part_boundary.'
Content-Type: image/gif; name="logo2.gif"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="logo2.gif"
Content-ID: <[email protected]>
<base64 encoded image here>
--'.$part_boundary.'--
--'.$main_boundary.'--
';
$mailsent = mail ($to, $subject, $message, $headers);
什么是重要的:
请将我们链接到您提到的潜在重复项。 – 2010-06-28 14:49:55
http://stackoverflow.com/questions/1851728/how-to-embed-images-in-html-email是一个例子..但就像我说的这些*不*给我我想要的,所以我是不知道为什么你想要一个链接到他们。 – ryeguy 2010-06-28 14:54:19