私の現在のプロジェクトでは、その場で PDF ファイルを作成し、メールの添付ファイルとして添付して送信する必要があります。それは正常に動作し、ファイルが生成され、私が提供した電子メールに送信されます。Microsoft Outlook または Windows Live アカウントに送信すると、PDF が添付されていますが、pdf でファイルを開くことができず、破損しているというエラーが表示されます。しかし、Gmail と Yahoo では問題なく動作します。誰もこれに対する解決策を持っていますか。以下は私のコードです
$dompdf = new DOMPDF();
$dompdf->load_html($message);
$dompdf->set_paper("a4", "landscape");
$dompdf->render();
// The next call will store the entire PDF as a string in $pdf
$pdf = $dompdf->output();
// You can now write $pdf to disk, store it in a database or stream it to the client.
file_put_contents("pdfs/invoice.pdf", $pdf);
$fileatt = "pdfs/invoice.pdf"; // Path to the file
$fileatt_type = "pdf"; // File Type
$fileatt_name = "invoice.pdf"; // Filename that will be used for the file as the 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");
}
誰かが問題を解決するのを手伝ってくれることを願っています。