在HTML电子邮件中嵌入图像

时间:2015-01-16 08:38:39

标签: php html image email

所以我一直在努力解决这个问题已经有一段时间了,并最终得到了一些工作。在某些电子邮件客户端上,这段代码显示正确嵌入的三个图像,一些将它们作为附件附加,而其他图像则不显示它们。我做错了什么以及如何解决它。

电子邮件是使用php的mail()发送的 - 功能如下:mail($_POST['email'],'Signature',$body,$header);

此外,在任何人拍摄之前,我知道这不是正确的编程习惯,但是这个脚本是一个本地脚本,只有我们才能访问简单生成的电子邮件签名。这就是为什么它根本没有进行任何输入验证或清理。

$header = 'From:webmaster@nobelis.co.za' . "\r\n";
            $header .= 'MIME-Version: 1.0' . "\r\n";
            $header .= 'Content-type:multipart/mixed; boundary="B_3504178637_3566343"' . "\r\n";
            $body = '> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--B_3504178637_3566343
Content-type: multipart/alternative;
    boundary="B_3504178637_3589184"


--B_3504178637_3589184
Content-type: text/plain;
    charset="US-ASCII"
Content-transfer-encoding: 7bit


Regards,

details





--B_3504178637_3589184
Content-type: text/html;
    charset="US-ASCII"
Content-transfer-encoding: quoted-printable

<table cellpadding="0" cellspacing="0" width="300">
<tr>
<td style="padding-right: 10px; border-bottom: 1px solid rgb(255, 255, 255);">
<img src="cid:E3FFCD1F-2201-4790-81B5-5F4F9B82A413" type="image/png" width="51" style="width:51px">
</td>
<td style="text-align: center; border-bottom: 1px solid rgb(221, 221, 221);">
<span style="color: rgb(31, 130, 197); font-family: Helvetica; font-size: 13px; line-height: 20px;">' . strtoupper($_POST['name']) . '</span><br>
<span style="color: rgb(102, 102, 102); font-family: Helvetica; font-size: 13px;">' . strtoupper($_POST['designation']) . '</span>
</td>
</tr>
<tr>
<td style="padding-right: 10px; border-bottom: 1px solid rgb(255, 255, 255); border-top: 1px solid rgb(255, 255, 255);">
<img src="cid:060EED13-21A7-4FF2-BDCE-D5A87BD2165B" type="image/png" width="51" style="width:51px">
</td>
<td style="text-align: center; border-bottom: 1px solid rgb(221, 221, 221);">
<span style="color: rgb(31, 130, 197); font-family: Helvetica; font-size: 13px; line-height: 20px;">CONTACT ME</span><br>
<span style="color: rgb(102, 102, 102); font-family: Helvetica; font-size: 10px;">T: ' . $_POST['telephone'] . ' | ' . ($_POST['fax'] != "" ? "F: " . $_POST['fax'] : ($_POST['cellphone'] != "" ? "C: " . $_POST['cellphone'] : "F:  086 694 0819")) . '</span>
</td>
</tr>
<tr>
<td style="padding-right: 10px; border-top: 1px solid rgb(255, 255, 255);">
<img src="cid:CA0B3207-4728-46DE-8BC7-72723443E97A" type="image/png" width="51" style="width:51px"></td>
<td style="text-align: center;">
<span style="color: rgb(31, 130, 197); font-family: Helvetica; font-size: 13px; line-height: 20px;">company name</span><br>
<span style="color: rgb(102, 102, 102); font-family: Helvetica; font-size: 10px;"><i>address</i></span>
</td>
</tr>
</table>

--B_3504178637_3589184--


--B_3504178637_3566343
Content-type: image/png; name="E3FFCD1F-2201-4790-81B5-5F4F9B82A413.png"
Content-ID: <E3FFCD1F-2201-4790-81B5-5F4F9B82A413>
Content-disposition: inline;
    filename="E3FFCD1F-2201-4790-81B5-5F4F9B82A413.png"
Content-transfer-encoding: base64

//base64 encoded image
--B_3504178637_3566343
Content-type: image/png; name="060EED13-21A7-4FF2-BDCE-D5A87BD2165B.png"
Content-ID: <060EED13-21A7-4FF2-BDCE-D5A87BD2165B>
Content-disposition: inline;
    filename="060EED13-21A7-4FF2-BDCE-D5A87BD2165B.png"
Content-transfer-encoding: base64


//base64 encoded image
--B_3504178637_3566343
Content-type: image/png; name="CA0B3207-4728-46DE-8BC7-72723443E97A.png"
Content-ID: <CA0B3207-4728-46DE-8BC7-72723443E97A>
Content-disposition: inline;
    filename="CA0B3207-4728-46DE-8BC7-72723443E97A.png"
Content-transfer-encoding: base64


//base64 encoded image
--B_3504178637_3566343--' . "\r\n";

2 个答案:

答案 0 :(得分:1)

使用PHPMailer类而不是mail()函数。它变得轻松而有力

答案 1 :(得分:0)

您应该使用multipart / related而不是multipart / mixed作为主要消息Content-type。