php PHPmailer 和 pdf 附件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19072038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHPmailer and pdf attachment
提问by FredV
I'm trying to send an email with a PDF attachment using the phpmailer class.
我正在尝试使用 phpmailer 类发送带有 PDF 附件的电子邮件。
I used this code:
我使用了这个代码:
Within mailTo
function:
在mailTo
功能:
$mail->AddAttachment($pdffile);
where $pdffile = $_SERVER['DOCUMENT_ROOT'] . "/facturen/test.pdf"
在哪里 $pdffile = $_SERVER['DOCUMENT_ROOT'] . "/facturen/test.pdf"
Sending the mail results in an email without attachment but with:
发送邮件的结果是一封没有附件但带有以下内容的电子邮件:
--b1_3768f40f33d9a5dec555d03a15af14f9
Content-Type: text/html; charset = "iso-8859-1"
Content-Transfer-Encoding: 8bit
at the top of my email and on the bottom of my email:
在我的电子邮件顶部和电子邮件底部:
--b1_3768f40f33d9a5dec555d03a15af14f9
Content-Type: application/octet-stream; name="test.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test.pdf"
JVBERi0xLjQKJcfsj6IKMTEgMCBvYmoKPDwvTGVuZ3RoIDEyIDAgUi9GaWx0ZXIgL0ZsYXRlRGVj
b2RlPj4Kc3RyZWFtCnic7VtZs9zEFa5A2CYpQyALSUiiNyQqI3pfeGOrOECgMJc8BPJg38Xbta8x
NqbyL/Jn85yvF6mPpNbMXMoPVCrlskvT6j59+izfWdT+pmG9UA0Lf4aH43ubt69x2dz8dsOb8Ofh
zY2zrGfeNU7yXmvf3Ns4wXrDxDhiHes50431vGdGlt8K741pjjfDiMEMbZuBgNHhp2qGLYbfxxvP
fa+9Gke8CTOG9flXoT8MZAaG1QOD8yMcb87e2sieCwXST3DUj/D3Tj7ytb/8bx751uaLzTcNV1r3
0kVtcy5Vr3ijmeqNwFzfc+51tgLVfHCx+XwT7SMIRbMgsUAZkzkPlFygBCq2V83D00jfOZAUJtE3
eHamwSoBJhvJlOidzfR1or97iXAWm/i8xBy0xHLZDytsfYXoPV2hNes9z0tcWgKxKq5NMA8RVJCn
QVzO6UjKaJxb6XTyJCa4yzcb1XNjjI
and so on...
等等...
How to resolve this?
如何解决这个问题?
回答by AkshayBandivadekar
Try this, it work for me ...
试试这个,它对我有用......
$mail->AddAttachment('path_to_pdf', $name = 'Name_for_pdf', $encoding = 'base64', $type = 'application/pdf');
In your case
在你的情况下
$mail->AddAttachment($_SERVER['DOCUMENT_ROOT'].'/facturen/test.pdf', $name = 'test', $encoding = 'base64', $type = 'application/pdf');
回答by Akinak
you can use three more parameters, all of which are optional:
您可以使用另外三个参数,所有这些都是可选的:
AddAttachment($path,$name,$encoding,$type);
also follow this answer: Send File Attachment from Form Using phpMailer and PHP
也请遵循以下答案:使用 phpMailer 和 PHP 从表单发送文件附件
There is an additional way to add an attachment. If you want to make a HTML e-mail with images incorporated into the desk, it's necessary to attach the image and then link the <img src="cid:CID" />
tag to it. For example, if you add an image as inline attachment with the CID my-photo, you would access it within the HTML e-mail with <img src="cid:my-photo" alt="my-photo" />
.
还有一种添加附件的方法。如果您想制作包含桌面图像的 HTML 电子邮件,则需要附加图像,然后将<img src="cid:CID" />
标签链接到它。例如,如果您将图像添加为 CID my-photo 的内嵌附件,您将在 HTML 电子邮件中使用<img src="cid:my-photo" alt="my-photo" />
.
In detail, here is the function to add an inline attachment:
详细来说,这里是添加内联附件的函数:
$mail->AddEmbeddedImage(filename, cid, name);
By using this function with this example's value above, results in this code:
通过将此函数与上述示例的值一起使用,可生成以下代码:
$mail->AddEmbeddedImage('my-photo.jpg', 'my-photo', 'my-photo.jpg ');
回答by Asped
Try this solution: Add attachment through PHPMailerIt seems totatly unrelated, but helped me too. THere must be problem with setting the Email body
试试这个解决方案: 通过 PHPMailer 添加附件这似乎完全无关,但也帮助了我。设置电子邮件正文肯定有问题