我通过PHP发送带有PDF附件的电子邮件。它适用于每个网络邮件,Thunderbird,Outlook,iOs,但在Mac OS X Mail应用程序中我有一个奇怪的行为:当我点击PDF附件时,它打开我在浏览器中发送电子邮件的网站主页。虽然如果我右键单击附件并选择在Acrobat PDF中打开它可以正常工作。其他带有PDF附件的电子邮件正按预期打开,因此它与某些邮件标题有关,而与软件配置无关。
A known issue是在浏览器中打开PDF而不是Acrobat PDF,如果它不会重定向到主页,就不会出现这样的问题。
以下是电子邮件来源的相关部分:
To: me@example.com
Subject: My email
X-PHP-Originating-Script: 10006:mail.inc.php
From: them@example.com
MIME-Version: 1.0
X-Mailer: Html Mime Mail Class
Content-Type: multipart/mixed;
boundary="=_02f1bb81e24e79ba7b9a88259d584c02"
Reply-to: them@example.com
This is a MIME encoded message.
--=_02f1bb81e24e79ba7b9a88259d584c02
Content-Type: multipart/alternative;
boundary="=_9bb751c17df5df4380796b97e7544792"
--=_9bb751c17df5df4380796b97e7544792
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
No text version was provided
--=_9bb751c17df5df4380796b97e7544792
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
[... html content ...]
--=_9bb751c17df5df4380796b97e7544792--
--=_02f1bb81e24e79ba7b9a88259d584c02
Content-Type: application/pdf;
name="my_pdf_file.pdf"
Content-Disposition: attachment; filename="my_pdf_file.pdf"
Content-Transfer-Encoding: base64
[... attachment in base 64 ...]
因此Content-Type
和Content-Disposition
已正确设置,但Apple Mail似乎忽略了Content-Disposition
。是否有其他标题可以设置为强制附件下载?
不确定它是否与问题相关,但我使用this mail class(HTML Mime Mail)进行了以下设置:
require_once("../../lib/HTMLMimeMail/mail.inc.php");
ob_start();
include('../../app/View/Email/myemail.php');
$bodyHtml = ob_get_contents();
ob_clean();
$subject = 'My email';
$_envoiMail = new html_mime_mail("X-Mailer: Html Mime Mail Class");
$_envoiMail->set_charset('utf-8');
$_envoiMail->add_html($bodyHtml, '');
$file_name = '../../../../uploads/my_pdf_file.pdf';
$attachment = $_envoiMail->get_file(dirname(__FILE__) . '/' . $file_name);
$_envoiMail->add_attachment($attachment, 'my_pdf_file.pdf', 'application/pdf');
$_envoiMail->build_message();
$_envoiMail->send('Me', 'me@example.com', 'Them', 'them@example.com', $subject, "Reply-to: them@example.com");