I am trying to create a pdf document using mpdf and in the first step I tried to save it in my downloads folder and then I tried to open it and it worked perfect. I can see what I need in the pdf document.
In the next step I tried to send the pdf as an attachment and the email was sent successfully with the pdf attachment but when I tried to open it from the mail its returning me an error something as "Adobe cannot open the pdf document because it is neither a supported file type or the file is damaged.......".
I searched for different questions in stackoverflow and I tried their valuable answers too but none of them helped me.
The below is the same question but the answer posted there too didn't helped me.
Stackoverflow questions related to my post
Here's my code:
$mpdf=new mPDF( );
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0;
$mpdf->WriteHTML($html,2);
ob_clean(); // **Tried this from Stackoverflow answers**
$mpdf->Output($filename.'.pdf', 'I');
$mailto = $row['Email1'].",".$row['Email5'];
$path = 'C:\\Users\\Downloads\\';
$file = $path."/".$filename;
$subject = 'Test Email';
$message = 'Test <br> Case';
$content = file_get_contents($file);
$content = chunk_split(base64_encode($content));
$separator = md5(time());
$eol = PHP_EOL;
$headers = "From: John <john.xxxxx@gmail.com>".$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"".$eol.$eol;
// message
$body .= "Content-Transfer-Encoding: 7bit".$eol;
$body .= "This is a MIME encoded message.".$eol;
$body = "--" . $separator.$eol;
$body .= "Content-Type: text/html; charset=\"UTF-8\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;
// attachment
$body .= "--" . $separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"" . $filename . '.pdf' . "\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol ;
$body .= $content.$eol;
$body .= "--" . $separator . "--";
//SEND Mail
if (mail($mailto, $subject, $body, $headers)) {
//echo "mail send ... OK"; // or use booleans here
}