PHPMailer AddStringAttachment与PDF [英] PHPMailer AddStringAttachment with PDF
问题描述
我是phpmailer的新手,我能够发送电子邮件,带附件的电子邮件以及.txt文件,但我无法发送带PDF的字符串附件.电子邮件已发送,但PDF已损坏/无法打开.任何人都可以帮助发送附件为PDF而不是.txt的AddStringAttachment吗?谢谢
I am new to phpmailer and I am able to send emails, emails with attachments, and stringattachments that are .txt files however I cannot send stringattachments with PDF's. The email is sent, but the PDF is corrupted/unable to open. Can anyone help to send the AddStringAttachment with the attachment being a PDF rather than a .txt? Thanks
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$body2 = "You are receiving this email because the Transfer Application submitted for $Name transferring to $Receiving is missing required documentation.
Please see the note below for details. The transfer application will not be reviewed until all of the necessary materials are received by the UHSAA.
<p> Details:
$Notes ";
$mail->IsSMTP();
$mail->AddAddress($emailp);
$mail->AddCC('transfers@uhsaa.org');
$mail->AddStringAttachment($body2, 'Filename.pdf', 'base64', 'application/octet-stream');
$mail->Subject = "Test";
$body = ("See attachment");
$mail->MsgHTML($body);
$mail->AddAddress($address);
$mail->AddCC($address);
if(!$mail->Send())
;
?>
同样,如果我只是将Filename.pdf更改为Filename.txt,则一切正常,因此我假设问题出在编码上,但我无法弄清楚.请帮助,以便我可以发送弦乐附件PDF.谢谢.
Again, if I just change Filename.pdf to Filename.txt everything works so I'm assuming the problem is with the encoding but I can't figure it out. Please help so I can send stringattachment PDF's. Thanks.
推荐答案
无需执行chunk_split base64编码pdf字符串
No need to chunk_split base64encode the pdf string just do
$mail->addStringAttachment($pdfString, 'vouchers.pdf');
这篇关于PHPMailer AddStringAttachment与PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!