Reputation: 647
I'm using mPDF to generate PDF's when a button is clicked and the i save them inside a folder. I am looking for a way to add the PDF to an attachment using PHPmailer. Here is what I've tried:
$dir = $_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF']);
$pdfexist = $dir."/classes/pdf/feestructure_".$student['rollno'].".pdf";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->From="[email protected]";
$mail->FromName="xyz";
$mail->addAddress("[email protected]");
//echo $email."<br/>";
$mail->addAddress("[email protected]");
$mail->addAddress("[email protected]");
$mail->Subject = 'XYZ';
$pdfstring = $pdfexist;
$mail->AddStringAttachment($pdfstring, "feestructure_".$roll.".pdf", $encoding = 'base64', $type = 'application/pdf');
The size of my generated pdf is 13k but its showing 1 k in mail attachment.help me guys.
Here is the output from mpdf:
$mpdf->WriteHTML(file_get_contents("$dir/feestructure_pdf.php?rollno=$rollno"));
$pdfname="feestructure_".$rollno.".pdf";
$mpdf->Output("classes/pdf/".$pdfname,"F");
Upvotes: 0
Views: 924
Reputation: 37710
Your $pdfexists
/ $pdfstring
variable contains a file path, not binary PDF data, so you should be using AddAttachment()
, not AddstringAttachment()
. AddAttachment attaches files (like your PDF), AddStringAttachment attaches strings, like what you might get back from a web call or a database.
$mail->AddAttachment($pdfstring, "feestructure_".$roll.".pdf", $encoding = 'base64', $type = 'application/pdf');
Upvotes: 2