我是phpmailer的新手,我能够发送电子邮件,带附件的电子邮件以及.txt文件的字符串附件但是我无法发送带PDF的字符串附件。电子邮件已发送,但PDF已损坏/无法打开。任何人都可以帮助发送AddStringAttachment,附件是PDF而不是.txt吗?感谢
<?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一切正常,那么我假设问题在于编码,但我无法弄明白。请帮忙,这样我就可以发送stringattachment PDF了。感谢。
答案 0 :(得分:11)
不需要chunk_split base64encode pdf字符串就可以了
$mail->addStringAttachment($pdfString, 'vouchers.pdf');
答案 1 :(得分:7)
尝试
$mail->AddStringAttachment($body2, 'Filename.pdf', 'base64', 'application/pdf');
它会起作用
答案 2 :(得分:1)
这对我来说很好:
$mail->addStringAttachment(base64_decode($attachmentBase64), $filename);