附加由dompdf创建的pdf并使用mime发送包含意外的字符串

问题描述 投票:0回答:1

我正在尝试使用dompdf创建一个文件并将其附加到mime而不保存。我从https://stackoverflow.com/a/12008553/9727103得到了答案,所以我使用它,但电子邮件包含一些不期望的东西。

这是我的部分代码。

$pdf = $dompdf->output();

$mm = new Mail_mime();

$msg = 'Hello world to all.';

$mm->setTxtBody($msg);
$mm->addAttachment($pdf,'application/pdf','output.pdf', false);

$body = $mm->get();
$subject = 'Hello World - ['.$customer.']';

$recipients = '[email protected]';
$headers['From']= '[email protected]'; 
$headers['To']= '[email protected]';
$headers['Subject'] = $subject;
$params['host'] = 'smtp.sendgrid.net';
$params['port'] = '587';
$params['auth'] = true;
$params['username'] = '[email protected]';
$params['password'] = '[email protected]';


$mail_object = Mail::factory('smtp', $params); // Print the parameters you are using to the page

// Send the message
$mail_object->send($recipients, $headers, $body);
if (PEAR::isError($mail_object)) {
    echo("<p>" . $mail_object->getMessage() . "</p>");
} else {
    echo("Message sent!");
}

它发送成功但我收到的电子邮件是这样的。

--=_0db58b483b7f7e450132520a9d0c50fe
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1

Hello World to all.
--=_0db58b483b7f7e450132520a9d0c50fe
Content-Transfer-Encoding: base64
Content-Type: application/pdf;
 name=output.pdf
Content-Disposition: attachment;
 filename=output.pdf;
 size=5444

JVBERi0xLjMKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZwovT3V0bGluZXMgMiAwIFIKL1BhZ2Vz
IDMgMCBSID4+CmVuZG9iagoyIDAgb2JqCjw8IC9UeXBlIC9PdXRsaW5lcyAvQ291bnQgMCA+Pgpl
bmRvYmoKMyAwIG9iago8PCAvVHlwZSAvUGFnZXMKL0tpZHMgWzYgMCBSCl0KL0NvdW50IDEKL1Jl
c291cmNlcyA8PAovUHJvY1NldCA0IDAgUgovRm9udCA8PCAKL0YxIDggMCBSCi9GMiA5IDAgUgo+
PgovWE9iamVjdCA8PCAKL0kxIDE0IDAgUgo+PgovRXh0R1N0YXRlIDw8IAovR1MxIDE1IDAgUgov
R1MyIDE2IDAgUgo+Pgo+PgovTWVkaWFCb3ggWzAuMDAwIDAuMDAwIDYxMi4wMDAgNzkyLjAwMF0K
ID4+CmVuZG9iago0IDAgb2JqClsvUERGIC9UZXh0IC9JbWFnZUMgXQplbmRvYmoKNSAwIG9iago8
PAovUHJvZHVjZXIgKP7/AGQAbwBtAHAAZABmACAAKwAgAEMAUABEAEYpCi9DcmVhdGlvbkRhdGUg
....

附加文件转换为字符串,有

Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1

我不打算这样做。当我使用https://www.freeformatter.com/base64-encoder.html#ad-output并复制pdf字符串并单击“解码并下载”时,它会下载我附加的pdf文件,但我希望它是带有附件的常规电子邮件。

有什么办法可以解决这个问题吗?任何帮助将不胜感激。谢谢!

php dompdf mime-mail
1个回答
0
投票

我想你错过了这一点。 PDF正确附加到您的电子邮件中。您的电子邮件(根据您的帖子)包含:

Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1

和:

Content-Transfer-Encoding: base64
Content-Type: application/pdf;
 name=output.pdf
Content-Disposition: attachment;
 filename=output.pdf;
 size=5444

如果您在电子邮件客户端中查看此电子邮件,您将看到PDF显示为附件,电子邮件中的消息将显示为“Hello World to all”。用纯文本(即没有格式化)。

© www.soinside.com 2019 - 2024. All rights reserved.