我正在尝试从Opencart发送带有附件的HTML电子邮件。有一个内置的功能$mail->addAttachment
。一切都很好,除了附件的位置是Apple Mail中的白框。在iOs Mail应用程序中,附件完全没有显示。在GMail上可以:
该附件在Apple Mail中也可用,因为如果我双击白色区域,则该附件正在打开。
这是在GMail中打开的消息的来源(我删除了X标头):
X-Mailer: PHP/5.4.39-0+deb7u2
Content-Type: multipart/related; boundary="----=_NextPart_fefb9509ef8523a96a17066ecf8472c8"
------=_NextPart_fefb9509ef8523a96a17066ecf8472c8
Content-Type: multipart/alternative; boundary="----=_NextPart_fefb9509ef8523a96a17066ecf8472c8_alt"
------=_NextPart_fefb9509ef8523a96a17066ecf8472c8_alt
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Some text (text/plain)
------=_NextPart_fefb9509ef8523a96a17066ecf8472c8_alt
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test title</title>
</head>
<body>
<p>Some html text(text/html)</p>
</body>
</html>
------=_NextPart_fefb9509ef8523a96a17066ecf8472c8_alt--
------=_NextPart_fefb9509ef8523a96a17066ecf8472c8
Content-Type: application/pdf; name="form.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="form.pdf"
Content-ID <%2Fhome%2Fhtml%2Fdownload%2form.pdf>
X-Attachment-Id: %2Fhome%2Fhtml%2Fdownload%2form.pdf
JVBERi0xLjMKJcTl8uXrp/Og0MTGCjQgMCBvYmoKPDwgL0xlbmd0aCA1IDAgUiAvRmlsdGVyIC9G
bGF0ZURlY29kZSA+PgpzdHJlYW0KeAGdW0tzHLcRvs+vQGInGbqk0bwfuTl2qqKkbMkRk1Q58mFJ
jkJylzvS7pIu8Q/o5oMuLlfpmB+Un5SvHwDmtdylSyXNAgM0uhuN7q8bo3fmO/POxPhTNIWp89Rs
WvMvszbPvtom5nxrEv6zPccIenvjxq34V2xWPHsVXJo3TCtLoiYr49ykdZQVpsjqqKqqxlR1GWWW
+jtQpUUTk5WmKjNzfmP+dGr+fAoStHKAlel9bLCyH1ympspqHRxHcRwn5vTcJDkP1cfpjXl2ekp8
...
------=_NextPart_fefb9509ef8523a96a17066ecf8472c8--
来自/system/library/mail.php的相关部分:
foreach ($this->attachments as $attachment) {
if (file_exists($attachment)) {
$handle = fopen($attachment, 'r');
$content = fread($handle, filesize($attachment));
fclose($handle);
$message .= '--' . $boundary . $this->newline;
$message .= 'Content-Type: application/pdf; name="' . basename($attachment) . '"' . $this->newline;
$message .= 'Content-Transfer-Encoding: base64' . $this->newline;
$message .= 'Content-Disposition: attachment; filename="' . basename($attachment) . '"' . $this->newline;
$message .= 'Content-ID: <' . basename(urlencode($attachment)) . '>' . $this->newline;
$message .= 'X-Attachment-Id: ' . basename(urlencode($attachment)) . $this->newline . $this->newline;
$message .= chunk_split(base64_encode($content));
}
}
编辑:
我只是意识到Content-ID和X-Attachment-Id是问题所在:
basename(urlencode($attachment)
应该:
urlencode(basename($attachment))
现在,它在Apple Mail中可以正常工作,但是附件在iOS(iPhone / iPad)上仍然丢失。任何的想法?
标头必须是这样的:
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=boundary42
在大多数情况下,发现缺少mime版本标记。您在边界上有错误,让我首先给具有规则部分的多部分实体的规则主体添加语法(仅重要部分):
multipart-body := [preamble CRLF] dash-boundary transport-padding CRLF body-part *encapsulation close-delimiter transport-padding [CRLF epilogue] dash-boundary := "--" boundary encapsulation := delimiter transport-padding CRLF body-part delimiter := CRLF dash-boundary close-delimiter := delimiter "--"
开头--
对于消息中使用的每个边界--
都是强制性的,结尾对于结束边界(close-delimiter)是强制性的。因此,具有boundary
以边界为三个主体部分的多部分主体如下所示:
--boundary42
Content-Type: text/plain; charset=us-ascii
...plain text version of message goes here....
--boundary42
Content-Type: text/richtext
.... richtext version of same message goes here ...
--boundary42
Content-Type: text/x-whatever
.... fanciest formatted version of same message goes here...
--boundary42--
阅读文档RFC
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句