sendmail - Receiving PDF File in Outlook -
in current project, have create pdf file on fly , attach mail attachment , send. works fine, file generate , send email provided. when send microsoft outlook or windows live account, pdf has attached can't open file pdf, gives , error saying, damaged. gmail , yahoo works fine. have solution this. below code
$dompdf = new dompdf(); $dompdf->load_html($message); $dompdf->set_paper("a4", "landscape"); $dompdf->render(); // next call store entire pdf string in $pdf $pdf = $dompdf->output(); // can write $pdf disk, store in database or stream client. file_put_contents("pdfs/invoice.pdf", $pdf); $fileatt = "pdfs/invoice.pdf"; // path file $fileatt_type = "pdf"; // file type $fileatt_name = "invoice.pdf"; // filename used file attachment $fp = fopen($fileatt, "rb"); $file = fread($fp, filesize($fileatt)); $file = chunk_split(base64_encode($file)); $num = md5(time()); $to = "mail@mail.com"; $subject = "invoice"; $headers = "from: " . "manager" . "<" . "mail@mail.com" . ">\r\n"; $headers .= "mime-version: 1.0\r\n"; $headers .= "content-type: multipart/mixed; "; $headers .= "boundary=".$num."\r\n"; $headers .= "--$num\r\n"; $headers .= "message-id: <" . gettimeofday() . " thesystem@" . $_server['server_name'] . ">\r\n"; $headers .= "x-mailer: php v" . phpversion() . "\r\n"; $headers .= "content-type:".$fileatt_type." "; $headers .= "name=\"".$fileatt_name."\"r\n"; $headers .= "content-transfer-encoding: base64\r\n"; $headers .= "content-disposition: attachment; "; $headers .= "filename=\"".$fileatt_name."\"\r\n"; $headers .= "".$file."\r\n"; $headers .= "--".$num."\r\n"; $headers .= "content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "".$message."\r\n"; $headers .= "--".$num."--"; if (mail($to, $subject, $message, $headers)) { fclose($fp); echo "success"; //header("location: client.php?m=1"); } else { echo "error"; //header("location: client.php?m=0"); } hope can me solve problem.
building own mime messages never idea. use phpmailer or swiftmailer instead. both handle heavy lifting of building messages, including file attachments. best of all, they're both free , work far far better built-in php mail function. code above reduced 5 of 6 lines of mail-sending-code either of packages.
Comments
Post a Comment