use*_*333 8 php pdf phpmailer email-attachments
我是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())
;
?>
Run Code Online (Sandbox Code Playgroud)
同样,如果我只是将Filename.pdf更改为Filename.txt一切正常,所以我假设问题是编码,但我无法弄明白.请帮忙,这样我就可以发送stringattachment PDF了.谢谢.
web*_*ter 11
不需要chunk_split base64encode pdf字符串就可以了
$mail->addStringAttachment($pdfString, 'vouchers.pdf');
Run Code Online (Sandbox Code Playgroud)
小智 7
尝试
$mail->AddStringAttachment($body2, 'Filename.pdf', 'base64', 'application/pdf');
Run Code Online (Sandbox Code Playgroud)
它会工作